Sonner
Brief toast notifications for success, errors, and background work. After add sonner, mount Toaster once in the root layout — without it, toast() shows nothing. Writing direction is passed through so layout flips in RTL.
Basic
Call toast() from sonner after mounting Toaster. Optional description and action.
Installation
CLI
Also needs
npm i lucide-react next-themes sonnerSetup
Required. Mount Toaster once in your root layout (inside ThemeProvider if you use one). Until you do, toast() will not appear.
Then mount
<Toaster /> in app/layout.tsxlayout.tsx
Composition
structure
Usage
sonner.tsx
Direction
Toaster reads useDirection and sets dir so toast text and actions follow LTR/RTL.
direction.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| theme | "light" · "dark" · "system" | from next-themes | On `Toaster` — color scheme for toast chrome. |
| dir | "ltr" · "rtl" | inherited | On `Toaster` — writing direction. Defaults from `useDirection`. |
| position | string | "bottom-right" | On `Toaster` or toast options — e.g. `"top-center"`, `"bottom-left"`. |
| toast() | (message, options?) => string · number | — | Imperative API from `sonner` — also `toast.success`, `.error`, `.promise`, etc. |