Headless mode
Learn how to build custom Inbox UI for your application using Novu custom hooks
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.
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.
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.