Skip to main content

What’s new in React v8+

v8+ of the Courier React SDK is a major update to Courier’s web SDK ecosystem. The latest update features:
  • A re-designed, modern UI by default with built-in dark mode support
  • Fully theme-able and customizable components
  • A much smaller JavaScript bundle with no third-party dependencies
React Inbox v8+ does not yet support the following:
  • Pins: Pinning a message to the top of the inbox
  • Tags: Managing categories of messages
If your app requires these features, we recommend continuing to use v7 at this time.

What’s in this guide

This guide includes migration steps for: All follow the same path to upgrade dependencies and authentication. After those steps, you may skip ahead to Toasts or Preferences if you don’t need to migrate Inbox components.

Migration Steps

1. Upgrade Dependencies

Courier React v8+ is available as a single package @trycourier/courier-react for React 18+ or @trycourier/courier-react-17 for React 17 support. The two packages contain the same functionality: the examples below work with either, and only one should be used in your app. Earlier versions of the Courier React SDKs required multiple packages (e.g. @trycourier/react-provider and @trycourier/react-inbox), which you should remove from your dependencies as part of this migration.
In your app’s package.json, remove existing @trycourier React dependencies:

2. Generate JWTs

If you’re already generating JWTs (JSON Web Tokens) to authenticate Courier SDKs, you can skip this step.
Courier React v8+ requires JWTs to authenticate connections to the Courier backends. JWTs are short-lived, signed tokens used to securely authenticate and authorize requests. They are the recommended way to connect to the Courier backend in all cases. Earlier verions of the Courier React SDKs accepted client keys (a stable Base64 encoded identifier) with or without an HMAC signature. JWT generation requires a private key and should be done in an environment where that key can be accessed securely, like your backend. A typical production JWT generation flow might look like this: JWT Authentication Flow Diagram
1

Your app calls your backend

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

Your backend calls Courier

In your backend, 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 app

Having received the JWT from Courier, your backend should return it to your app and pass it to the Courier SDK.

Testing JWTs in Development

To quickly get up and running with JWTs in development, you can use cURL to call the Courier Issue Token Endpoint directly.

3. Authenticate the Courier SDK

Replace instances of <CourierProvider> with a single call to courier.shared.signIn(), a method accessible through the singleton exposed with useCourier().
The Courier SDK shares authentication between components, so only one call to courier.shared.signIn is needed in an app.If you’re only using Courier toasts, skip ahead to Upgrade Toast Components to see this authentication example for <CourierToast>.
App.tsx

4. Upgrade Inbox components

4a. Theming

v8+ removes the dependency on styled-components and supports theming natively. A few examples of how the theme definition has changed are below. For a complete reference while migrating, see the v7 theme and the v8+ theme types.
App.tsx
Dark Mode
React Inbox v8+ improves support for dark mode with automatic switching between light and dark modes based on system preferences.
App.tsx

4b. Custom Components

Most components in the default UI can be overridden with custom components. Some prop names and method signatures to pass components have changed in v8+. An example is shown here. See the Courier React docs for more examples of using custom components and customizing user interactions in React v8+.
App.tsx
Custom Component Prop Changes
Inbox Components: Note: In v8+, renderHeader receives CourierInboxHeaderFactoryProps which contains a feeds array (not feedType). Each feed has feedId, title, iconSVG, tabs, and isSelected properties.

4c. React Hooks

Message tags and pins are not yet supported in v8+. If your app requires tagging or pinning we recommend continuing to use v7 at this time.
Use cases with custom UIs may require fetching messages and maintaining the inbox state manually via hooks. Courier’s React hooks are now included in @trycourier/courier-react. Remove any dependency on @trycourier/react-hooks.
package.json
Update uses of useInbox() to useCourier() and update changed method signatures. A few common examples are shown here. The full set of updated hooks is below.
App.tsx
Method Signature Changes

4d. Feeds and Tabs

v8+ introduces a new feeds and tabs system for organizing messages into logical groups and filtered views. A feed is a container that groups related tabs together. Each tab represents a filtered view of messages within a feed. What’s New:
  • Feeds: Organize tabs into logical sections (e.g., “Inbox”, “Archive”, “Notifications”)
  • Tabs: Provide filtered views of messages (e.g., “All”, “Unread”, “Important”)
  • Datasets: Each tab corresponds to a dataset identified by a unique datasetId
Using Feeds with Components: Pass a feeds prop to <CourierInbox> to configure feeds and tabs:
App.tsx
Using Feeds with Hooks: When using hooks, register feeds with inbox.registerFeeds() and access messages by datasetId:
App.tsx
Migration from v7: In v7, messages were accessed via inbox.messages. In v8+:
  • Messages are organized by datasetId in inbox.feeds[datasetId].messages
  • Use inbox.registerFeeds() to configure feeds and tabs
  • Use inbox.listenForUpdates() to enable real-time updates
  • Use datasetId (not feedType) when calling fetchNextPageOfMessages()
For complete documentation on feeds and tabs, see the Courier React docs.

5. Upgrade Toast Components

Courier React v8+ includes a redesigned Toast component with improved customization, theming, and dark mode support. The migration from v7 Toast involves updating the component usage, props, and theming structure. Authenticating the SDK for Toasts Replace instances of <CourierProvider> with a single call to courier.shared.signIn(), a method accessible through the singleton exposed with useCourier().
If you’ve already authenticated for Courier Inbox, you only need to replace blocks of <CourierProvider>...</CourierProvider> with the <CourierToast> component.The Courier SDK shares authentication between components, so only one call to courier.shared.signIn is needed in an app.
App.tsx

5a. Toast Props

Some props passed to <CourierToast> to configure behavior have changed or moved in v8+. Below is the mapping from v7 to v8+. Props for theming, custom components, and handling user interaction are detailed below.

5b. Theming

v8+ removes the dependency on the styled-components package and supports theming natively. A few examples of how the theme definition has changed are below. For a complete reference while migrating, see the v7 theme and v8+ theme types.
App.tsx
Dark Mode
React Toast v8+ improves support for dark mode with fully customizable theming and automatic switching between light and dark modes based on system preferences. For a complete reference while migrating, see the Courier React v8+ theme type.
App.tsx

5c. Custom Components

v8+ introduces two render props to use components when your integration requires customization beyond theming:
  • renderToastItemContent: Customize the content area while keeping the default styles, animations, and dismiss functionality.
  • renderToastItem: Customize the complete appearance and behavior of the toast items and stack.
See the Courier React docs for more examples of using custom components and customizing user interactions in React v8+.

5d. React Hooks

Use cases with custom UIs may require maintaining the toast state manually via hooks. Courier’s React hooks are now included in @trycourier/courier-react. Remove any dependency on @trycourier/react-hooks.
package.json
Update uses of useToast() to useCourier() and update changed method signatures. Example usage and the full set of updated hooks is below.
App.tsx
Method Signature Changes
config and clientKey info are removed from hooks in v8+.

6. Upgrade Preferences Components

Courier React v8+ replaces the v7 <PreferencesV4> component (from @trycourier/react-preferences) with <CourierPreferences>, which shares the redesigned UI, native theming, and dark mode support of the other v8+ components. Authenticating the SDK for Preferences As with Inbox and Toast, replace <CourierProvider> with a single call to courier.shared.signIn(). If you’ve already authenticated for another v8+ component, no additional sign-in is needed — the SDK shares authentication across components.
Preferences requires a JWT that includes the read:preferences and write:preferences scopes.
App.tsx

6a. Preferences Props

The v7 <PreferencesV4> component only accepted two props — tenantId and draft. It had no theming props; its colors were derived internally from the brand configured on the fetched preference page. In v8+, tenant scoping moves to signIn (there’s no per-component prop), draft-preview is not yet available, and <CourierPreferences> adds native client-side theming and other options.
Set tenantId on signIn to scope everything — both <CourierPreferences> and the headless useCourier().preferences hooks — to that tenant. There’s no per-component tenant prop; the signed-in tenant flows through automatically.

6b. Theming

Like Inbox and Toast, v8+ Preferences removes the dependency on styled-components and supports theming natively through lightTheme and darkTheme props. See the full CourierPreferencesTheme reference for the available fields.

6c. React Hooks

Custom preferences UIs that used the v7 usePreferences() hook from @trycourier/react-hooks should migrate to useCourier().preferences. Courier’s React hooks are now included in @trycourier/courier-react. Remove any dependency on @trycourier/react-hooks.
App.tsx
Method Signature Changes
config and clientKey info are removed from hooks in v8+. Tenant scoping moves from a per-call tenantId argument to signIn.
See the Preferences methods reference in the React SDK docs for full signatures and a working example.

v7 Documentation

Documentation for v7 and below of the Courier React SDKs can be found at:

Markdown Rendering

Courier React versions 1.13.0 through 7.x.x automatically render Markdown-formatted messages, such as those output when Markdown Rendering is enabled for the Courier Inbox provider. v8+ of the Courier React SDK does not include Markdown rendering support by default, however it can be implemented with custom Inbox components. The following example uses the markdown-to-jsx package.
package.json
App.tsx

More Information

Questions, answers, and troubleshooting info that may come up while migrating. Can I migrate one of Inbox or Toasts without migrating the other? You must migrate both at the same time. The React v8+ SDK depends on a newer major version of the @trycourier/courier-js SDK than previous Courier React SDKs. Running both versions on the same page is not recommended and may result in unexpected issues. I don’t see any requests to the Courier backend after upgrading. This may be caused by multiple versions of the upgraded packages installed at once. Make sure only the latest version of each @trycourier/ package is installed. You may need to run npm dedupe, yarn dedupe or the equivalent command for your package manager to remove older conflicting versions. See github.com/@trycourier/courier-web/issues/92 for more information. If you have more questions while upgrading, please open an issue on GitHub or reach out to Courier Support.