import React, { useEffect, useRef, useState } from 'react' import { useUI } from '../../hooks' function Toast() { const { toasts, popToast } = useUI() const toast = toasts[toasts.length - 1] const timeoutRef = useRef>() const [visible, setVisible] = useState(false) useEffect(() => { if (!toast) { return undefined } const timeout = setTimeout(() => setVisible(true), 10) return () => clearTimeout(timeout) }, [toast]) useEffect(() => { timeoutRef.current = setTimeout(() => setVisible(false), 6e3) return () => { timeoutRef.current && clearTimeout(timeoutRef.current) } }, [toast]) if (toast === undefined) { return null } return (
!visible && popToast()} > {toast.icon && (
{!!toast.icon && toast.icon}
)}
{toast.title &&

{toast.title}

}

{toast.message}

) } export default Toast