---
title: "How to Use openstatus React Widget"
url: "https://www.openstatus.dev/docs/guides/how-to-use-react-widget"
date: "2018-10-20"
author: "openstatus"
description: "Add an openstatus status widget to your React or Next.js app with the @openstatus/react package as a React Server Component, or build your own with the typed fetch helper."
category: "Guides"
agent:
  instructions: "Search openstatus docs, guides, blog and product pages. Replace {query} with URL-encoded keywords or a question. Returns markdown with links to matching pages, not a generated answer."
  endpoint: "https://www.openstatus.dev/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://www.openstatus.dev/.well-known/search"
---

Install the [npm](https://www.npmjs.com/package/@openstatus/react) package:

```bash
npm install @openstatus/react
```

## React server component

```tsx

export function Page() {
  return ;
}
```

It will automatically attach the slug to the href to allow the user to open a new tab on click to `https://slug.openstatus.dev`. If you want to redirect to a specific page, use the `href` property:

```tsx

```

> **Note**
>
> `StatusWidget` is an **async function** and will only work with RSC. Using it within a plain React app will not work.

### Styling

#### With Tailwind CSS

The widget is styled with Tailwind utility classes, so Tailwind has to scan the published package
for them.

**Tailwind v4** — add a `@source` directive to the CSS file that imports Tailwind:

```css
/* app/globals.css */
@import "tailwindcss";
@source "../node_modules/@openstatus/react/dist";
```

**Tailwind v3** — add the package to `content`:

```js
// tailwind.config.js
module.exports = {
  content: [
    "./app/**/*.{tsx,ts,mdx,md}",
    "./node_modules/@openstatus/react/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};
```

#### Without Tailwind CSS

```tsx
// app/layout.tsx

```

## Typed fetch function

```tsx

// React Server Component
async function CustomStatusWidget() {
  const res = await getStatus("slug");
  // ^StatusResponse = { status: Status }

  const { status } = res;
  // ^Status = "unknown" | "operational" | "degraded_performance" | "partial_outage" | "major_outage" | "under_maintenance" | "incident"

  return 

{/* customize */}

;
}
```

`getStatus` never throws: a network failure or a non-`2xx` response degrades to
`{ status: "unknown" }` rather than bubbling an error into your page.

### Pointing at a self-hosted API

Both `getStatus` and `StatusWidget` call `https://api.openstatus.dev` by default. If you self-host
openstatus, set `OPENSTATUS_API_URL` on the server — that is the only lever for `StatusWidget`,
which takes just `slug` and `href`. `getStatus` additionally accepts the base URL as a second
argument:

```tsx
const res = await getStatus("slug", "https://api.status.example.com");
```

The variable is read at request time and has no `NEXT_PUBLIC_` prefix, so a prebuilt image can be
pointed at a different API without rebuilding.