import { useEffect, useRef } from 'react'; import { Icon } from '@/app/Icon'; import { TOAST_DURATION } from '@/lib/config'; interface ToastProps { message: string; variant?: 'success' | 'error'; onDone: () => void; } export function Toast({ message, variant = 'success', onDone }: ToastProps) { // Call sites pass an inline `onDone` arrow, so a plain `[message, onDone]` dependency array // restarts the auto-dismiss timer on every unrelated parent re-render (e.g. typing in an // unrelated field after the toast appears) instead of only when a NEW message is shown. const onDoneRef = useRef(onDone); useEffect(() => { onDoneRef.current = onDone; }); useEffect(() => { if (!message) return undefined; const timer = window.setTimeout(() => onDoneRef.current(), TOAST_DURATION); return () => window.clearTimeout(timer); }, [message]); if (!message) return null; return (