Observe notification summary information

Ask the Community

How to use the notification API to observe the number of unread notifications


Overview #

This method allows you to observe the count of unread notifications for the current user, including live updates.
React:
import { notification } from '@cord-sdk/react';
const counts = notification.useNotificationCounts({
      filter: {
          metadata: { flavor: 'minty' },
          location: { page: 'bookmarks' },
          groupID: 'group123',
       },
    });

return (
  <div>
     {!counts && "Loading..."}
     {counts && (
       <p>Unread notifications: {counts.unread}</p>
      )}
  </div>
 );
Vanilla JavaScript:
const ref = window.CordSDK.notification.observeNotificationCounts(
  (counts) => {
       console.log("Unread notifications", counts.unread);
  },
  { filter: {
        metadata: { flavor: 'minty' },
        location: { page: 'bookmarks' },
        groupID: 'group123',
   }}
);
import { notification } from '@cord-sdk/react';
const counts = notification.useNotificationCounts({
      filter: {
          metadata: { flavor: 'minty' },
          location: { page: 'bookmarks' },
          groupID: 'group123',
       },
    });

return (
  <div>
     {!counts && "Loading..."}
     {counts && (
       <p>Unread notifications: {counts.unread}</p>
      )}
  </div>
 );
Copy

Available Data #

Graphic showing example uses of the Cord Notification Counts API

The API provides an object which has the following fields:


unread #

number
The number of notifications that the current user hasn't seen yet.

What this function returns #

A reference number which can be passed to unobserveSummary to stop observing notification summary information.

Arguments this function takes #


options #

optional
ObserveNotificationSummaryOptions

This is an object with the following fields:

Show property details


Not finding the answer you need? Ask our Developer Community

Ask Cordy