Fix toast auto-dismiss and add debugging
- Added console logging to debug toast lifecycle - Improved toast ID generation with timestamp - Limited toasts to max 3 at a time - Toasts should now auto-dismiss after 3 seconds
This commit is contained in:
@@ -15,8 +15,15 @@ interface ToastProps {
|
||||
export default function Toast({ message, type, onClose, duration = 3000 }: ToastProps) {
|
||||
useEffect(() => {
|
||||
if (duration > 0) {
|
||||
const timer = setTimeout(onClose, duration)
|
||||
return () => clearTimeout(timer)
|
||||
console.log(`[Toast] Setting timer for ${duration}ms`)
|
||||
const timer = setTimeout(() => {
|
||||
console.log('[Toast] Auto-dismissing')
|
||||
onClose()
|
||||
}, duration)
|
||||
return () => {
|
||||
console.log('[Toast] Clearing timer')
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}
|
||||
}, [duration, onClose])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user