Skip to main content
Courier React Inbox The Courier React SDK provides ready-made components and programmatic hooks for building notification experiences:
  • <CourierInbox /> — full-featured inbox for displaying and managing messages
  • <CourierInboxPopupMenu /> — popup menu version of the inbox
  • <CourierToast /> — toast notifications for time-sensitive alerts
  • <CourierPreferences /> — notification preferences center for managing topic subscriptions and delivery
  • useCourier() — hook for programmatic access and custom UIs
See these components in action with 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.If you’re coming from an earlier version of the Courier React SDK, check out the v8 migration guide for what’s changed, how to upgrade your app, and links to documentation for past versions of the React SDK.
Not using React? Check out the @trycourier/courier-ui-inbox and @trycourier/courier-ui-toast packages instead, which provide Web Components for any JavaScript project.

Authentication

To use the SDK, you need to generate a JWT (JSON Web Token) for your user. This JWT should always be generated by your backend server, never in client-side code.
1

Your client calls your backend

When your app needs to authenticate a user, your client should make a request to your own backend (ex. GET https://your-awesome-app.com/api/generate-courier-jwt).
2

Your backend calls Courier

In your backend endpoint, use your Courier API Key to call the Courier Issue Token Endpoint and generate a JWT for the user.
3

Your backend returns the JWT to your client

Having received the JWT from Courier, your backend should return it to your client and pass it to the Courier SDK.
For a step-by-step walkthrough of authentication and token generation, see our JWT authentication tutorial.

Development testing with cURL

To quickly test JWT generation for development only, you can call the Issue Token Endpoint directly.
Do not call the Issue Token API from client-side code. Always keep your Courier API keys secure.

Quick Start

Get up and running with Courier React in minutes. This minimal example shows how to add the inbox component to your app.
Follow the inbox implementation tutorial for detailed step-by-step guidance including backend JWT generation.

Inbox Component

<CourierInbox />

Preview of the default CourierInbox component

Default CourierInbox component

If you’re using tenants, scope requests to a particular tenant by passing its ID to signIn:
For the full reference of sign in parameters, see the Courier JS docs.
Getting Started: Follow the step-by-step inbox implementation tutorial, or see a complete working example in our React Inbox sample app.

<CourierInboxPopupMenu />

Preview of the default CourierInboxPopupMenu component

Default CourierInboxPopupMenu component


Tabs and Feeds

Tabs and feeds organize and filter messages in the inbox. A feed is a container that groups related tabs together. Each tab applies filters to show relevant messages.
If there is only one feed, the feed selection dropdown is hidden. If a feed has only one tab, the tab bar is hidden and the unread count appears next to the feed.
Filter options for each tab:
Preview of CourierInbox with tabs

CourierInbox with many tabs

You can also define multiple feeds to organize messages into different categories. Each feed appears as a selectable option in the inbox header.
Preview of CourierInbox with feeds

CourierInbox with many feeds


Handle Clicks and Presses

onMessageLongPress is only applicable on devices that support touch events.

Styles and Theming

Customize the inbox to match your app with a theme object. You can customize fonts, icons, text, and more.
Courier React Inbox with a custom unread indicator style

Courier React Inbox with a custom unread indicator style

Theme utilities: defaultLightTheme / defaultDarkTheme provide the default inbox themes, and mergeTheme(baseTheme, overrideTheme) merges two themes with the override taking precedence.
The full CourierInboxTheme type is below. Every property is optional; only override what you need. It covers the popup trigger button, the inbox window (header, feeds, tabs, actions), the message list (items, scrollbar, menus), and loading/empty/error states.
Customizing the popup menu's alignment, position, and dimensions

Customizing the popup menu's alignment, position, and dimensions

Fixed height

<CourierInbox /> has a default height of auto. Set a fixed height with the height prop:

Custom Elements

You can customize individual parts of the inbox by passing render props. Each render prop receives typed props and returns a ReactNode. You can also use React refs (CourierInboxElement, CourierInboxPopupMenuElement) for programmatic access to component methods like removeHeader().
Subsequent pages of messages are loaded automatically when the user scrolls to the bottom of the inbox, so the pagination component may only be visible briefly.

Toast Component

<CourierToast />

Courier Toast component

Toasts are short-lived notifications that notify users and prompt them to take action. The Toast component is connected to the feed of Courier Inbox messages.
Toasts are synced with the Inbox message feed. You can use both components together to provide persistent and temporary notifications.
Sample App: See a complete working example in our React Toast sample app.
Some initialization for toasts is asynchronous. If your app displays toasts immediately when the component is mounted, consider using the onReady callback (see props table below) to wait until the component is fully initialized.

Handle Clicks

Courier Toast with action buttons

If a message contains actions, toast items include a button for each. Use onToastItemActionClick to handle those clicks.

Styles and Theming

Courier Toast with a custom theme

Toast theme utilities: defaultToastLightTheme / defaultToastDarkTheme for defaults, and mergeToastTheme(baseTheme, overrideTheme) to merge.

Custom Elements


CourierToast Props

Toast component with auto-dismiss enabled

Enabling autoDismiss adds a countdown bar to each toast and automatically removes it after the timeout. The countdown bar color is theme-able via autoDismissBarColor in CourierToastTheme.

Using onReady

If toasts display immediately on mount or custom render functions don’t apply correctly, use onReady to wait for full initialization before authenticating:

Preferences Component

<CourierPreferences />

The Preferences component lets your users manage which topics they’re subscribed to and how each topic is delivered (per-channel routing and digest schedules), directly inside your React app.
Authentication requires a JWT that includes the read:preferences and write:preferences scopes. Always generate JWTs on your backend — see Authentication.

CourierPreferences Props


Styles and Theming

Pass a CourierPreferencesTheme to lightTheme and/or darkTheme. Themes are merged with the defaults, so you only specify the values you want to override.
Preferences theme utilities: defaultPreferencesLightTheme / defaultPreferencesDarkTheme for defaults, and mergePreferencesTheme(mode, overrideTheme) to merge. See the full CourierPreferencesTheme reference.

useCourier Hook

The useCourier() hook provides programmatic access to Courier functionality for building custom UIs or integrating Courier features into existing components.

When to use hooks vs components

  • Components (<CourierInbox />, <CourierToast />): Quick integration with default UI
  • Hooks (useCourier()): Custom UIs, programmatic control, advanced state management
  • Both together: Use hooks for state management while components handle rendering

Hook return value

Complete example — authentication, inbox setup, real-time updates, and displaying messages:
You must call inbox.listenForUpdates() after authentication to enable real-time message updates. Without this, the inbox only shows messages from the initial load.

Inbox methods

Toast methods

Preferences methods

Use the preferences hook to read and update a user’s notification preferences programmatically — for example, to build a custom preferences UI in place of the <CourierPreferences /> component.
Reading and updating preferences requires a JWT with the read:preferences and write:preferences scopes. Always generate JWTs on your backend — see Authentication.
Error handling: Check inbox.error and toast.error for error states:
Sample Apps: See complete working examples in our React Hooks sample app and React Inbox sample app.

Advanced

Next.js and SSR

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

Troubleshooting

Make sure you’ve called inbox.listenForUpdates() after authentication. This establishes the WebSocket connection required for real-time updates.
Possible causes:
  1. Not authenticated — ensure signIn() has been called
  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: Ensure the JWT is generated correctly on your backend
  • Expired JWT: JWTs have an expiration time; generate a new one
  • Missing scopes: Ensure your JWT includes inbox:read:messages and inbox:write:events
  • Wrong user ID: Verify the userId matches the user the JWT was issued for
Import types directly from the package:
Ensure you’re using 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'), include only necessary scopes.
  • Performance: Use canUseCache: true (default) for cached data. Use datasetIds to load only needed datasets. Set appropriate setPaginationLimit() values. The hook’s reactive state updates automatically; avoid triggering unnecessary re-renders.
  • Testing: Mock useCourier() in tests to return test data:

EU and regional endpoints

Only needed if your workspace uses the EU datacenter. @trycourier/courier-react re-exports EU_COURIER_API_URLS and getCourierApiUrlsForRegion from @trycourier/courier-js.
Mint JWTs on a backend that calls the EU Issue Token host: https://api.eu.courier.com/auth/issue-token. Full detail: Courier JS — EU and regional endpoints.
You can use apiUrls: EU_COURIER_API_URLS instead of getCourierApiUrlsForRegion("eu") if you prefer the frozen preset.

TypeScript Types