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.
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:
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.