Skip to main content
Courier React Inbox

What’s Included

The Courier React SDK provides both ready-made components and programmatic hooks for building notification experiences: Components:
  • <CourierInbox /> provides a full-featured inbox component for displaying and managing messages.
  • <CourierInboxPopupMenu /> offers a popup menu version of the inbox.
  • <CourierToast /> displays toast notifications for time-sensitive alerts.
Hooks:
  • The useCourier() hook enables programmatic access to Courier functionality for building custom UIs.
See the Inbox Component, Toast Component, and Using Hooks pages for detailed documentation.

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.
npm install @trycourier/courier-react
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.

JWT Authentication Flow

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 Authentication with cURL

To quickly test JWT generation for development only, you can use cURL to call the Courier Issue Token Endpoint directly.
Do not call the Issue Token API from client-side code. Always keep your Courier API keys secure.
curl --request POST \
     --url https://api.courier.com/auth/issue-token \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer $YOUR_API_KEY' \
     --header 'Content-Type: application/json' \
     --data \
 '{
    "scope": "user_id:$YOUR_USER_ID write:user-tokens inbox:read:messages inbox:write:events read:preferences write:preferences read:brands",
    "expires_in": "$YOUR_NUMBER days"
  }'

Quick Start

Get up and running with Courier React in minutes. This minimal example shows how to add the inbox component to your app.
"use client"

import { useEffect } from "react";
import { CourierInbox, useCourier } from "@trycourier/courier-react";

export default function App() {
  const courier = useCourier();

  useEffect(() => {
    // Generate a JWT for your user on your backend server
    const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";

    // Authenticate the user
    courier.shared.signIn({
      userId: $YOUR_USER_ID,
      jwt: jwt,
    });
  }, []);

  return <CourierInbox />;
}
Next Steps:

TypeScript Types

InboxMessage

Represents a single message in the inbox.

InboxDataSet

Represents a dataset of messages with pagination information. This is the structure returned by inbox.feeds[datasetId] and inbox.fetchNextPageOfMessages().

CourierInboxFeed

Defines a feed (container for tabs) in the inbox.

CourierInboxTab

Defines a tab (filtered view) within a feed.

CourierInboxDatasetFilter

Defines filters for messages. Filters are combined with AND logic, meaning all specified conditions must be met.

CourierToastItemFactoryProps

Props passed to custom toast item render functions.