Skip to main content
Build a fully custom notification inbox with Novu’s headless React hooks without being constrained by the default <Inbox /> UI or dependencies. The @novu/react package provides a set of hooks, such as useNotifications and useCounts. You handle the layout, styling, and interactions, while Novu provides the notification state, real-time updates, and actions.
Not using React? You can access the same data manually using the JavaScript SDK.

Install the React SDK package

Run the following command in your terminal:

Add the NovuProvider

Wrap your application or the components that need access to notifications with the NovuProvider. This component initializes the Novu client and provides it to all child hooks via context.
For more NovuProvider options, such as HMAC encryption, see the Novu provider documentation.

Fetch and display notifications

Use the useNotifications hook to fetch and display a list of notifications. The hook manages loading states, pagination (hasMore, fetchMore), and real-time updates for you.

Show notification counts

A common use case is showing a badge with the unread count on a bell icon. The useCounts hook is designed for this. It fetches unread, unseen, or total counts and updates them in real-time.

Adding notification actions

To perform actions on notifications such as marking as read, unread, or archiving, you can use the useNovu hook. This hook gives you direct access to the Novu client instance to call its API methods. The hooks useNotifications and useCounts automatically refetch and update your UI when these actions are performed.

Showing product updates banner

@novu/react hooks can be used to show a product updates banner in your application along with <Inbox /> component notifications. Differences between product update banner and <Inbox /> component notifications are:
  • <Inbox /> component notifications are displayed in Popover when bell is clicked while product update banner is displayed as a standalone top banner in the application.
  • <Inbox /> component notifications are unique to the user while product update banner is displayed to all users.
To show a product update banner use following steps:
  1. Create a new workflow in the dashboard with in-app steps
  2. Edit in-app step content and make this workflow as critical so that this workflow is not displayed in preferences.
  3. Create a system subscriber in the dashboard with subscriberId product-updates-subscriber for product updates banner. This system subscriber will be used to show the product updates banner to all users.
  4. Create ProductUpdateBanner component and use useNotifications hook to get the product updates notifications and show them in the banner.
components/ProductUpdateBanner.tsx
  1. Use ProductUpdateBanner component in your application. In below example we are using ProductUpdateBanner component with <Inbox /> component to show the product updates banner along with <Inbox > notifications.
components/NovuNotifications.tsx
  1. Use NovuNotifications component in your application.
  2. Trigger the step 1 workflow to system subscriber product-updates-subscriber.
  3. As per product release requirements, Permanently delete or archive the product update notification to hide the banner.
Using above steps, two instances of Novu notifications will be shown in your application:
  • Product updates banner with common subscriberId product-updates-subscriber
  • <Inbox /> notifications with user specific subscriberId YOUR_SUBSCRIBER_ID

Real-time updates

The useNotifications and useCounts hooks automatically listen for real-time events and update your component state. If you need to listen for events manually, then you can use the novu.on() method from the useNovu hook. For example, you might want to show a toast notification when a new message arrives.

Using websocket events

The websocket event notifications.notification_received can be used to play a sound and show a toast message on the screen when a notification is received.