"use client"; import { createContext, type ReactNode, useCallback, useContext, useState } from "react"; type Toast = { id: number; kind: "info" | "error" | "success"; text: string }; const Ctx = createContext<{ push: (kind: Toast["kind"], text: string) => void }>({ push: () => {} }); export function ToastProvider({ children }: { children: ReactNode }) { const [items, setItems] = useState([]); const push = useCallback((kind: Toast["kind"], text: string) => { const id = Date.now() + Math.random(); setItems((x) => [...x, { id, kind, text }]); setTimeout(() => setItems((x) => x.filter((t) => t.id !== id)), 6000); }, []); return ( {children}
{items.map((t) => (
{t.text}
))}
); } export const useToast = () => useContext(Ctx);