import * as Toast from '@radix-ui/react-toast'; import type { Dispatch, FC, PropsWithChildren, ReactNode, SetStateAction, } from 'react'; import { createContext, useEffect, useState } from 'react'; import Notification from '@/components/Common/Notification'; type NotificationContextType = { message: string | ReactNode; duration: number; } | null; type NotificationProps = { viewportClassName?: string }; const NotificationContext = createContext(null); export const NotificationDispatch = createContext< Dispatch> >(() => {}); export const NotificationProvider: FC> = ({ viewportClassName, children, }) => { const [notification, dispatch] = useState(null); useEffect(() => { const timeout = setTimeout(() => dispatch(null), notification?.duration); return () => clearTimeout(timeout); }, [notification]); return ( {children} {notification && ( {notification.message} )} ); };