'use client' import { createContext, useCallback, useContext, useState, type ReactNode } from 'react' type ToastFn = (msg: string, type?: 'success' | 'error') => void const ToastCtx = createContext(() => {}) export function useToast() { return useContext(ToastCtx) } export function ToastProvider({ children }: { children: ReactNode }) { const [state, setState] = useState<{ msg: string; type: 'success' | 'error' } | null>(null) const show = useCallback((m, type = 'success') => { setState({ msg: m, type }) setTimeout(() => setState(null), type === 'error' ? 4500 : 2800) }, []) return ( {children} {state && (
{state.msg}
)}
) }