Guides

useUnreadNotificationCount

useUnreadNotificationsCount is a React Hook that let you know the number of unread notifications.

const { unreadNotificationCount, loading, clear } = useUnreadNotificationCount({ profileId })

Usage

import { useUnreadNotificationCount } from '@lens-protocol/react-web';


function NotificationsCount({ profileId }: { profileId: string }) {
  const { unreadNotificationCount, loading, clear } = useUnreadNotificationCount({ profileId })
  
  if (loading) return null;

  return (
    <div>
     <p>You have {unreadNotificationCount} unread notifications</p>
     <button onClick={clear}>Clear</button>
    </div>
  )
}

Reference

useUnreadNotificationCount(args)

const { unreadNotificationCount, loading, clear } = useUnreadNotificationCount({ profileId });

Parameters

  • profileId: string the profile Id you are interested in.

Returns

{
  unreadNotificationCount: number;
  loading: boolean; // whether unreadNotificationCount is readable or not
  clear: () => Promise<void>; // function to clear the counter
}