diff --git a/src/components/NotificationsProvider.tsx b/src/components/NotificationsProvider.tsx index 2e1c9cc1..2348a8cf 100644 --- a/src/components/NotificationsProvider.tsx +++ b/src/components/NotificationsProvider.tsx @@ -1,5 +1,5 @@ import React from 'react' -import {ReactNode, useReducer} from 'react' +import {ReactNode, useReducer, useCallback} from 'react' import notificationsReducer from '../reducers/notifications/reducer' import {NewNotification} from '../reducers/notifications/types' import {dismissNotification, dismissNotifications, notify} from '../reducers/notifications/actions' @@ -13,13 +13,16 @@ export const NotificationsProvider = (props: Props) => { const [notifications, dispatch] = useReducer(notificationsReducer(), []) const context = { notifications, - notify: (notification: NewNotification) => { - const action = notify(notification) - dispatch(action) - return action.payload - }, - dismissNotification: (id: string) => dispatch(dismissNotification(id)), - dismissNotifications: () => dispatch(dismissNotifications()), + notify: useCallback( + (notification: NewNotification) => { + const action = notify(notification) + dispatch(action) + return action.payload + }, + [dispatch] + ), + dismissNotification: useCallback((id: string) => dispatch(dismissNotification(id)), [dispatch]), + dismissNotifications: useCallback(() => dispatch(dismissNotifications()), [dispatch]), } return {props.children}