ToastProvider component wraps your application and provides toast functionality to all child components. It automatically listens for flash messages from Inertia.js and manages the toast state.
Setup
Wrap your application with theToastProvider component, typically in your root layout:
Props
The React components to render inside the provider. This is typically your entire application or layout.
Optional configuration object to customize toast behavior and appearance.
Default duration in milliseconds that toasts remain visible. Set to
0 to disable auto-dismiss.Default position where toasts appear on screen.Options:
top-righttop-lefttop-centerbottom-rightbottom-leftbottom-center
Maximum number of toasts that can be displayed simultaneously. Older toasts are automatically removed when this limit is exceeded.
The key name used to read toast data from Inertia flash messages. This should match the key used in your Laravel backend.
Configuration examples
Custom position and duration
Disable auto-dismiss
Custom flash message key
If you’re using a custom key in your Laravel backend:Limit visible toasts
Context value
TheToastProvider creates a context that provides the following values to child components via the useToast hook:
Array of currently active toast items.
The merged configuration object combining defaults and user-provided overrides.
Function to display a success toast.
Function to display an error toast.
Function to display an info toast.
Function to display a warning toast.
Function to remove a specific toast by its ID.
Function to remove all active toasts.
TypeScript types
The
ToastProvider automatically listens for Inertia.js flash messages and displays them as toasts. Make sure your Laravel backend is configured to send toast data in the flash session.