Installation
In your React.js project, install the following dependency: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:
INFOCourier 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.comwss://1x60p1o3h8.execute-api.us-east-1.amazonaws.com
https://inbox.courier.comwss://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.
<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
openedevent will fire for that message. Theopenedevent will only fire once per message. - Messages can be marked as
readandunreadby the user, which will fire the corresponding events. - Messages can be marked as
archivedby 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
clickedevent and also mark the message asread.
Toast Component
The<Toast> component displays a toast message when a new message has been received.
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.