import { useEffect, useState } from "react"; import type { Toast as ToastType } from "../types"; export default function Toast({ toasts, remove }: { toasts: ToastType[]; remove: (id: number) => void }) { return (
{toasts.map((t) => ( ))}
); } function ToastItem({ toast, remove }: { toast: ToastType; remove: (id: number) => void }) { const [show, setShow] = useState(false); useEffect(() => { requestAnimationFrame(() => setShow(true)); const timer = setTimeout(() => { setShow(false); setTimeout(() => remove(toast.id), 300); }, 3000); return () => clearTimeout(timer); }, [toast.id, remove]); return (
{toast.message}
); }