The useNovu hook is used to obtain the Novu instance, which allows you to interact with the headless SDK interface.

useNovu returns

The Novu class instance.

Example usage

The below example demonstrates how to use the useNovu hook to listen for new notifications and show a toast notification.

import { useNovu } from '@novu/react/hooks';

const NotificationToast = () => {
  const novu = useNovu();

  useEffect(() => {
    const listener = ({ result: notification }) => {
      // Show a toast notification
    };

    novu.on('notifications.notification_received', listener);

    return () => {
      novu.off('notifications.notification_received', listener);
    };
  }, [novu]);

  return null;
};