useToast hook.
Installation
First, install the React package:Setup
1
Wrap your app with ToastProvider
In your main application file (typically
app.jsx or app.tsx), import and wrap your application with the ToastProvider:The
ToastProvider automatically listens to Inertia’s flash event and displays toasts from your Laravel backend.2
Configure the provider (optional)
Using the hook
TheuseToast hook provides methods to programmatically create toasts from your React components.
Basic usage
Available methods
TheuseToast hook returns an object with the following methods:
success(message, options?)
Displays a success toast.
error(message, options?)
Displays an error toast.
info(message, options?)
Displays an info toast.
warning(message, options?)
Displays a warning toast.
Toast options
You can customize individual toasts using theoptions parameter:
TypeScript support
The package is written in TypeScript and includes full type definitions:Advanced usage
Custom toast wrapper
You can create a custom wrapper component with predefined settings:Context access
For advanced use cases, you can access theToastContext directly:
Next steps
Styling
Customize the appearance of your toasts
Laravel setup
Configure Laravel to send toast notifications