Skip to main content
The React SDK wraps Courier’s in-app components as React components, plus one hook that exposes the client behind them.
  • <CourierInbox /> and <CourierInboxPopupMenu />, an inbox as a panel or a popup
  • <CourierToast />, toasts for messages that arrive while the app is open
  • <CourierPreferences />, a preference center for topic subscriptions
  • useCourier(), the client, for custom UIs and for driving the components from outside
The components behave identically on every web framework, so this page doesn’t repeat their reference. Install and sign in here, then follow for what each component does. Every code sample there has a React tab.
See these components in the interactive Inbox demo. No setup required.

Installation

Available on GitHub and npm. Courier publishes two React packages: @trycourier/courier-react for React 18+ and @trycourier/courier-react-17 for React 17.
This is the latest version of the Courier React SDK, recommended for new and existing apps.Coming from an earlier version? The covers what changed, how to upgrade, and docs for past versions.
Not using React? Use the and packages instead. They provide Web Components for any JavaScript project.

Authentication

Courier authenticates with a JWT that your backend mints with your Courier API key, never in client code. is the full guide: the token flow, scope strings, reading auth state, signing out, token refresh, and EU-hosted workspaces.

Quick start

Add the inbox component to your app.
Scope requests to one by passing its ID to signIn:

Component reference

Each component’s props, theme, callbacks, and custom-render surface live with the feature. These links open on the React tab. The CourierInboxTheme, CourierToastTheme, and CourierPreferencesTheme objects are the same on React, Vue, Angular, and the Web Components, so each is documented once: , , .

useCourier hook

useCourier() returns the Courier client and the three component surfaces. Use it to build your own UI, or to drive a prebuilt component from outside it.
Components and the hook aren’t a choice between two integrations. The components call the same client the hook returns, so a page can render <CourierInbox /> and read inbox.totalUnreadCount for a badge elsewhere in the same tree. Call inbox.listenForUpdates() after you authenticate. It opens the realtime connection, which nothing else in a custom UI calls for you. Without it, the inbox loads once and doesn’t update again.

Advanced

Next.js and SSR

Courier Inbox and Toast support Next.js but render client-side only. In Next.js 13+, add 'use client' to the top of any file using Courier components.

Troubleshooting

Call inbox.listenForUpdates() after authentication. It opens the WebSocket connection required for real-time updates.
Possible causes:
  1. Not authenticated: call signIn()
  2. Feeds not registered: call registerFeeds() before load()
  3. Network errors: check inbox.error for details
  4. JWT expired: generate a new token
  • Invalid JWT: generate the JWT correctly on your backend
  • Expired JWT: JWTs expire. Generate a new one
  • Missing scopes: include inbox:read:messages and inbox:write:events in the JWT
  • Wrong user ID: the userId must match the user the JWT was issued for
Two tabs sharing a datasetId collapse into one dataset. Every datasetId has to be unique across all feeds, not only within one. See .
Import types directly from the package:
Use the correct package:
  • React 18+: @trycourier/courier-react
  • React 17: @trycourier/courier-react-17

Best practices

  • JWT security: always generate JWTs server-side. Cache on the client, refresh before expiration (standard: '1d'), and include only the scopes you need.
  • Performance: canUseCache: true (default) serves cached data. Use datasetIds to load only the datasets you need, and set a suitable setPaginationLimit(). The hook’s reactive state updates on its own, so avoid unnecessary re-renders.
  • Testing: mock useCourier() in tests to return test data:

EU and regional endpoints

Only needed if your workspace uses the . @trycourier/courier-react re-exports EU_COURIER_API_URLS, DEFAULT_COURIER_API_URLS, and getCourierApiUrlsForRegion from @trycourier/courier-js. Pass the result as apiUrls on sign-in. For the hostnames, the helper semantics, and the same-region JWT requirement, see .

TypeScript types