import { useState, useEffect, useCallback } from 'react'; import { CheckCircle, XCircle, X } from 'lucide-react'; export interface Toast { message: string; type: 'success' | 'error'; } export function useToast() { const [toast, setToast] = useState(null); useEffect(() => { if (!toast) return; const t = setTimeout(() => setToast(null), 3000); return () => clearTimeout(t); }, [toast]); const showToast = useCallback((message: string, type: 'success' | 'error' = 'success') => { setToast({ message, type }); }, []); const ToastComponent = () => { if (!toast) return null; const isSuccess = toast.type === 'success'; return (
{isSuccess ? : } {toast.message}
); }; return { toast, showToast, ToastComponent }; }