Skip to main content
Learn how to integrate Laravel Inertia Toast with React. This guide covers provider setup, component configuration, and usage of the 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)

You can customize the default behavior by passing a config prop:

Configuration options

Using the hook

The useToast hook provides methods to programmatically create toasts from your React components.

Basic usage

Available methods

The useToast 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 the options 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 the ToastContext directly:
Direct context access is for advanced use cases. It is unnecessary and highly discouraged. Use the useToast hook for most scenarios.

Next steps

Styling

Customize the appearance of your toasts

Laravel setup

Configure Laravel to send toast notifications