Overview
The Toast component displays temporary notification messages. It uses Radix UI Toast primitives and includes a powerfuluseToast hook for programmatic control.
Import
Setup
Add theToaster component to your app root:
useToast Hook
The primary way to display toast notifications programmatically.Returns
Function to display a new toast notification. See toast function signature below.
Array of currently active toast notifications.
Function to dismiss a toast. If no ID is provided, dismisses all toasts.
toast() Function
Call thetoast function to display a notification:
The title of the toast notification.
The description/body content of the toast.
The visual style variant of the toast:
default: Standard success styling with green themesuccess: Success message with check icon and green themeerror: Error message with warning icon and red themewarning: Warning message with info icon and yellow themeinfo: Info message with info icon and blue themeinfo2: Alternative info styling with different blue theme
Optional action button element to display in the toast.
Duration in milliseconds before the toast auto-dismisses. If not provided, toast persists until manually dismissed.
Controlled open state of the toast.
Callback fired when the open state changes.
Return Value
Thetoast() function returns an object with:
Unique identifier for the toast instance.
Function to dismiss this specific toast.
Function to update the toast properties after creation.
Usage Examples
Toast Component
Low-level component for rendering toast notifications. Typically used through theuseToast hook.
Props
The title text of the toast.
The description content of the toast.
The visual style variant.
Additional CSS classes to apply.
Ref to the underlying Radix Toast element.
Radix UI Props
ExtendsReact.ComponentPropsWithoutRef<typeof ToastPrimitives.Root>, inheriting Radix Toast props including:
openonOpenChangedurationtype
Configuration
Toast Limits
Remove Delay
Accessibility
- Toasts use Radix UI’s accessible toast primitives
- Proper ARIA attributes for screen readers
- Keyboard navigation support
- Focus management when toasts appear
- Swipe gestures for mobile dismissal
Icon Variants
Each variant displays a corresponding icon:success: Check icon in green containererror: Triangle alert icon in red containerwarning: Info icon in yellow containerinfo: Info icon in blue containerinfo2: Info icon in alternative blue containerdefault: No icon displayed