Installation
Usage
Toast requires two main components: theToaster component to display toasts, and the useToaster hook to manage toast state.
Components
Toaster
The container component that renders and animates toasts.Array of toast objects to display. Managed by the
useToaster hook.Function to remove a toast by ID. Provided by the
useToaster hook.Sets the left position of the toast container. Useful for responsive positioning on small screens.
useToaster Hook
A React hook that manages toast state and provides methods to add and remove toasts. Returns:Current array of active toasts.
Method to add a new toast to the stack.
Method to remove a toast by its ID.
Toast Push Options
When callingtoaster.push(), you can provide these options:
Content to display in the toast.
Visual style and semantic meaning:
neutral: General informationsuccess: Successful actionswarning: Warnings or cautionserror: Errors or failures
Time in milliseconds before the toast auto-dismisses. If not provided, toast must be manually dismissed.
Custom ID for the toast. Auto-generated if not provided.
Callback function when the toast is dismissed.
Whether to focus the toast when rendered. Automatically set for the first toast in the stack.
Toast Component Props
The individual Toast component (used internally by Toaster) accepts these props:The visual style of the toast.
Content to display in the toast.
Callback when the dismiss button is clicked.
Accessible label for the dismiss button.
Icon label for error variant.
Icon label for neutral variant.
Icon label for success variant.
Icon label for warning variant.
Element name for customization.
Examples
Success Toast
Error Toast
Warning Toast
Toast with Action
Toast with Custom Dismiss Callback
Manually Dismissing Toasts
Multiple Toasts
Positioning
Toasts appear at the bottom-right of the viewport by default. You can adjust positioning for responsive layouts:Accessibility
- Toasts automatically receive focus when displayed to ensure screen reader announcement
- Each variant includes an appropriate icon with accessible labeling
- The dismiss button includes a screen reader label
- When a toast is dismissed, focus returns to the element that triggered it
- Multiple toasts are announced in order
- Toasts use
role="status"for non-critical messages to avoid interrupting screen readers
Best Practices
- Use toasts for immediate feedback to user actions (saves, deletions, etc.)
- Keep toast messages short and action-oriented
- Use appropriate variants to match the action result
- Set reasonable
dismissAftertimes (3-5 seconds for success, longer for errors) - Don’t require user action within a toast - they’re temporary
- Avoid showing multiple toasts simultaneously when possible
- For critical information that shouldn’t disappear, use Alert instead
- Don’t use toasts for passive notifications unrelated to user actions
- Include links to relevant pages when appropriate
- Test with screen readers to ensure announcements are clear