useNotifications
Learn how to use the useNotifications hook to fetch and manage notifications in your React application
The useNotifications hook provides a way to fetch and manage notifications in your application. It includes support for pagination, filtering, and real-time updates.
Hook Parameters
---type-table--- ../../types/react-types.ts#UseNotificationsProps ---end---
Return Value
---type-table--- ../../types/react-types.ts#UseNotificationsResult ---end---
Notification Type
The Notification type from @novu/react includes many properties. Here are the most commonly used ones:
---type-table--- ../../types/react-types.ts#NotificationType ---end---
Example Usage
Here's how to use the useNotifications hook to fetch and display notifications:
With Filtering
You can filter notifications by various properties:
read- Filter notifications by read statusseen- Filter notifications by seen statustags- Filter notifications by tags. If multiple tags are provided, Novu evaluates them usingORlogic, meaning a notification is included if it contains at least one of the specified tags.data- Filter notifications by data attributes (key-value pairs).severity- Filter notifications by severitylimit- Fetch notifications per pagecreatedGte- Fetch notifications created after the given date (in milliseconds)createdLte- Fetch notifications created before the given date (in milliseconds)
With Infinite Scroll
You can implement infinite scroll using the fetchMore function:
Using Notification Actions
The hook provides several actions to manage notifications:
Real-time notifications updates
The notifications list is automatically updated in real-time when new notifications arrive or when notifications state (read, seen, archived, snoozed) changes.