Sonner is an opinionated toast component for React, designed to be beautiful by default and simple to use. It emphasizes accessibility and provides a modern look and feel, inspired by macOS notifications. The library is currently stable at version 2.0.7 and receives regular updates, often with multiple patch releases between minor or major versions. Its key differentiators include built-in support for various toast types (success, error, info, warning, loading), rich customization options through props, and a strong focus on developer experience with a simple `toast()` API. Unlike some alternatives, Sonner aims to provide a consistent, aesthetically pleasing experience without requiring extensive styling, while still offering flexibility for specific needs. It also excels at handling asynchronous operations with its promise-based toast updates.
npm install sonnerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up the Toaster component, trigger various toast types (simple, success, loading, error), and programmatically dismiss a toast using its ID.
Consult the official Sonner documentation (sonner.emilkowal.ski) for specific migration paths and updated prop names. Update your code to use the new API surface.
Ensure you are on version 2.0.5 or newer. The correct way to import the styles is typically `import 'sonner/dist/style.css';` in your main entry file or component.
Upgrade to v2.0.7 or newer. If you need multiple distinct toast display areas, use the `toasterId` prop on each `<Toaster />` instance: `<Toaster toasterId="my-first-toaster" />`.
Upgrade Sonner to v2.0.4 or a newer version to ensure the `onDismiss` callback fires correctly upon toast dismissal.
Upgrade to v2.0.2 or newer. Always provide a toast ID when calling `toast.dismiss(id)` for targeted removals. For global dismissal (dismissing the last toast without an ID), upgrade is necessary.
Ensure you have `import 'sonner/dist/style.css';` in your root `App.js`/`App.tsx` or `index.js`/`index.tsx` file. Verify your bundler configuration supports CSS imports.
Ensure you are using `import { toast } from 'sonner';` and that the import statement is at the top of your file. Check for typos in the function call.Confirm you are importing it as a named export: `import { Toaster } from 'sonner';`. Ensure you have `<Toaster />` present in your component tree.Wrap the component rendering toasts in a `useEffect` hook with an empty dependency array to ensure it only runs on the client, or use a dynamic import with `ssr: false` if using Next.js or similar frameworks.