Skip to main content
The 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 the ToastProvider component, typically in your root layout:

Props

React.ReactNode
required
The React components to render inside the provider. This is typically your entire application or layout.
Partial<ToastConfig>
Optional configuration object to customize toast behavior and appearance.
number
default:"5000"
Default duration in milliseconds that toasts remain visible. Set to 0 to disable auto-dismiss.
string
default:"top-right"
Default position where toasts appear on screen.Options:
  • top-right
  • top-left
  • top-center
  • bottom-right
  • bottom-left
  • bottom-center
number
default:"5"
Maximum number of toasts that can be displayed simultaneously. Older toasts are automatically removed when this limit is exceeded.
string
default:"toasts"
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

The ToastProvider creates a context that provides the following values to child components via the useToast hook:
ToastItem[]
Array of currently active toast items.
ToastConfig
The merged configuration object combining defaults and user-provided overrides.
(message: string, options?: ToastOptions) => void
Function to display a success toast.
(message: string, options?: ToastOptions) => void
Function to display an error toast.
(message: string, options?: ToastOptions) => void
Function to display an info toast.
(message: string, options?: ToastOptions) => void
Function to display a warning toast.
(id: string) => void
Function to remove a specific toast by its ID.
() => void
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.