Inbox for React.js Web SDK
Learn how to integrate the Courier Inbox React SDK to deliver in-app notifications seamlessly in your React applications. Explore setup, customization, and best practices for notification delivery.
Installation
In your React.js project, install the following dependency:
or
The react-provider
component is required in order to use other components like react-inbox
and react-toast
and is responsible for authentication, API calls and state management.
You can initialize the react-provider
in your app like this:
INFO
Courier React components utilize specific endpoint URLs that may require inclusion in the site’s Content Security Policy (CSP) records.
courier-react < v5.0.0
https://fxw3r7gdm9.execute-api.us-east-1.amazonaws.com
wss://1x60p1o3h8.execute-api.us-east-1.amazonaws.com
**courier-react v5.0.0 + **
https://inbox.courier.com
wss://realtime.courier.com
Authentication
There are two methods for handling authentication: JWT and HMAC. JWT is our recommended method, HMAC is being deprecated.
JWT Auth Enabled
HMAC Auth Enabled
Inbox Component
The <Inbox>
React component displays list of recent notifications that the user has received.
or
In order to use <Inbox>
you need to ensure that it is included in the component tree below where you have defined the <CourierProvider>
(read more about React Context). Here’s a simple example:
Events
Each message in the inbox supports the following events:
- When the Inbox is opened and a message is in view, an
opened
event will fire for that message. Theopened
event will only fire once per message. - Messages can be marked as
read
andunread
by the user, which will fire the corresponding events. - Messages can be marked as
archived
by the user, which will fire the corresponding event. Archived messages will not be returned when fetching messages from the API. - If “Click Tracking” is enabled, clicking a message that has an action will created a
clicked
event and also mark the message asread
.
Github Docs: @trycourier/react-inbox
Toast Component
The <Toast>
component displays a toast message when a new message has been received.
or
Github Docs: @trycourier/react-toast
React Hooks
React Hooks (useInbox
, useToast
, useCourier
) exist as a separate package so that you can build your own interface using our api and state management without having to install all the dependencies that @trycourier/react-inbox
or other react-dom based packages include.
This also enables using this package with react-native in a much simpler way.
useInbox
Github Docs: @trycourier/react-hooks
useToast
If you do not want to use Courier to trigger a toast notification then you can always invoke the toast locally with the useToast hook. Below is an example creating a notification from the client rather than creating it from a transport. Do not forget to wrap this component with a CourierProvider somewhere up the component hierarchy chain.
Github Docs: @trycourier/react-toast