Skip to main content

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#

PropertyTypeDescription
tagsTagsFilter
dataRecord<string, unknown>
readboolean
archivedboolean
snoozedboolean
seenboolean
severitySeverityLevelEnum | SeverityLevelEnum[]
createdGtenumber
createdLtenumber
limitnumber
realtimebooleanWhen false, disables the WebSocket subscription that auto-injects newly received notifications into the list. Built-in mutations like readAll, seenAll, archiveAll, and archiveAllRead continue to update local state. Use this when you want to drive new-notification updates yourself (e.g. via your own novu.on('notifications.notification_received', ...) handler combined with refetch()). When set, this prop takes precedence over the realtime config on <NovuProvider />. When omitted, the provider value (default true) is used.
onSuccess(data: Notification[]) => void
onError(error: NovuError) => void

Return Value#

PropertyTypeDescription
notificationsNotification[]
errorNovuError
isLoadingboolean
isFetchingboolean
hasMoreboolean
readAll() => Promise<{ data?: void | undefined; error?: NovuError | undefined; }>
seenAll() => Promise<{ data?: void | undefined; error?: NovuError | undefined; }>
archiveAll() => Promise<{ data?: void | undefined; error?: NovuError | undefined; }>
archiveAllRead() => Promise<{ data?: void | undefined; error?: NovuError | undefined; }>
refetch() => Promise<void>
fetchMore() => Promise<void>

Notification Type#

The Notification type from @novu/react includes many properties. Here are the most commonly used ones:

PropertyTypeDescription
idstring
transactionIdstring
subjectstring
bodystring
toSubscriber
isReadboolean
isSeenboolean
isArchivedboolean
isSnoozedboolean
snoozedUntilstring
deliveredAtstring[]
createdAtstring
readAtstring
firstSeenAtstring
archivedAtstring
avatarstring
primaryActionAction
secondaryActionAction
channelTypeChannelType
tagsstring[]
redirectRedirect
dataNotificationData
workflowWorkflow
severitySeverityLevelEnum
read() => Result<Notification>
unread() => Result<Notification>
seen() => Result<Notification>
archive() => Result<Notification>
unarchive() => Result<Notification>
delete() => Result<void>
snooze(snoozeUntil: string) => Result<Notification>
unsnooze() => Result<Notification>
completePrimary() => Result<Notification>
completeSecondary() => Result<Notification>
revertPrimary() => Result<Notification>
revertSecondary() => Result<Notification>
on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => () => void
off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => void

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 status
  • seen - Filter notifications by seen status
  • tags - Filter notifications by tags. If multiple tags are provided, Novu evaluates them using OR logic, 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 severity
  • limit - Fetch notifications per page
  • createdGte - 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.