Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Sonner examples · Standard

Error Toast Sonner for React

A button that shows an error toast with the error icon.

Framework
UI library

An error toast tells people an action failed. The button calls toast.error, and Toaster adds its error icon. Say what failed and what to do next, since a bare Something went wrong leaves people guessing.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does this demo show an error toast?

The button calls toast.error with "Something went wrong". That sets the type to error. Toaster draws an OctagonXIcon with className="size-4" and aria-hidden.

Which options does this call pass?

Only that message. There is no description, duration, action, or custom icon in this file. The whole notice is the string passed to toast.error.

How do I add what failed under the title?

Pass description as the second argument to toast.error. It renders under the title. This demo does not pass one, so the title is the only line.

How do I add a Retry button?

Pass action with a label and an onClick in the second argument. The button runs onClick and then closes the toast. This call does not pass action.

How long does this error stay up?

This call does not pass duration. The toast uses duration on Toaster, or 4 seconds when Toaster omits it too. Pass duration on this call when this notice should stay longer.

Where is the error icon defined?

Toaster sets icons.error to OctagonXIcon. Pass icon on toast.error when this toast needs a different one. The demo renders its own Toaster; in an app, render one near the root.