import { createContext, useContext, useState, useCallback } from 'react'; const ToastContext = createContext(); export function ToastProvider({ children }) { const [toasts, setToasts] = useState([]); const addToast = useCallback((message, type = 'info', duration = 3000) => { const id = Date.now(); setToasts(prev => [...prev, { id, message, type }]); if (duration > 0) { setTimeout(() => { setToasts(prev => prev.filter(t => t.id !== id)); }, duration); } }, []); const removeToast = useCallback((id) => { setToasts(prev => prev.filter(t => t.id !== id)); }, []); return ( {children}
{toasts.map(toast => (
{toast.message}
))}
); } export const useToast = () => useContext(ToastContext);