import { Meta } from '@storybook/blocks'; # NotificationProvider The `NotificationProvider` provides state and react dispatch method for building NotificationGroup like component. ## Provides It internally uses `useReducer` hook from React to provide a state and a dispatch method to update this state. ### State ```javascript [{ // The uuid generated while adding the notification to the state array id?: string; // The severity of notification, Severity enum contains ERROR, SUCCESS, INFO, and WARNING severity?: Severity; // The message to display in the notification message?: string; // Whether or not the notification should be closed automatically autoClose?: boolean; // Auto close delay in milliseconds, it defaults to 6000 (6s) autoCloseDelay?: number; // Whether or not the current notification array (state) should be emptied replaceAll?: boolean; }] ``` You can access the state using `useNotificationState` hook. ### Dispatch Method ```javascript dispatch: React.Dispatch ``` You can access the dispatch method using `useNotificationDispatch` hook. ## Usage ```jsx import React from 'react'; import { NotificationProvider, useNotificationState, useNotificationDispatch, Notification } from 'amazon-chime-sdk-component-library-react'; const App = () => ( ); const NotificationGroup = () => { const { notifications } = useNotificationState(); const dispatch = useNotificationDispatch(); const notificationItems = {notifications.map(({ id, ...rest }): any => ( dispatch({ type: ActionType.REMOVE, payload: id })} /> ))}; return ( <> {notificationItems} ) } ``` **Note**: Check [useNotificationState](/docs/ui-hooks-notification-usenotificationstate--page) and [useNotificationDispatch](/docs/ui-hooks-notification-usenotificationdispatch--page) for more information.