toast.dismiss() for graceful dismissal with animations, and toast.remove() for instant removal.
toast.dismiss()
Thetoast.dismiss() function triggers the exit animation and marks the toast for removal. The toast will be removed from the DOM after the unmountDelay period.
Dismiss a Single Toast
Pass the toast ID to dismiss a specific toast:Dismiss All Toasts
Calltoast.dismiss() without any arguments to dismiss all active toasts:
toast.remove()
Thetoast.remove() function immediately removes toasts from the DOM without triggering exit animations.
Remove a Single Toast
Remove All Toasts
Key Differences
| Feature | toast.dismiss() | toast.remove() |
|---|---|---|
| Animation | Triggers exit animation | No animation |
| Timing | Waits for unmountDelay | Instant removal |
| Use Case | Graceful dismissal | Immediate cleanup |
| User Experience | Smooth | Abrupt |
unmountDelay
TheunmountDelay option controls how long to wait (in milliseconds) before removing a dismissed toast from the DOM. This allows time for exit animations to complete.
Default Behavior
The defaultunmountDelay is 500ms (from src/core/defaults.ts:15):
Custom unmountDelay
Set a custom delay per toast:Use with Custom Animations
Match theunmountDelay to your CSS animation duration:
Practical Examples
Auto-dismiss After Action
Manual Dismiss Button
Clear All Notifications Button
Dismiss on Navigation
Conditional Dismiss
Timeout with Manual Dismiss
Implementation Details
Fromsrc/core/toast.ts:51-56 and src/core/toast.ts:87-92:
DISMISS_TOAST: Setsvisible: false, triggers animations, waits forunmountDelayREMOVE_TOAST: Immediately removes the toast from the store
Best Practices
Use dismiss() for better UX
Use dismiss() for better UX
Prefer
toast.dismiss() over toast.remove() in most cases to provide smooth exit animations:Match unmountDelay to animations
Match unmountDelay to animations
Set
unmountDelay to match your CSS animation duration:Always dismiss loading toasts
Always dismiss loading toasts
Ensure loading toasts are always dismissed or updated:
Use remove() for cleanup only
Use remove() for cleanup only
Reserve
toast.remove() for situations where you need immediate cleanup: