import { useEffect, useRef } from 'react'; import { faX } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Notification as NotificationType } from './NotificationProvider'; interface NotificationProps { notification: Required; clearNotification: (text: string) => void; } const Notification = ({ notification, clearNotification }: NotificationProps) => { const timeout = useRef(); const handleClearNotification = () => clearNotification(notification.text); const setNotifTimeout = () => { timeout.current = window.setTimeout( handleClearNotification, notification.timeoutMs ); }; const cancelNotifTimeout = () => { clearTimeout(timeout.current); }; useEffect(() => { setNotifTimeout(); return cancelNotifTimeout; }, []); return (
{notification.type === 'error' && (
)} {notification.type === 'success' && (
)} {notification.type === 'info' && (
)}

{notification.text}

); }; export default Notification;