Make your AI a shadcn expert

Shadcn Toast

React toast for save confirms, undo, and async status. Built with TypeScript and Tailwind CSS for Next.js using Base UI — stacked, swipe to dismiss, promise states.

A toast is a short message that appears, then goes away. Use it for “Saved”, undo, or a promise that is still running. If the message must stay on the page until they act, that is an Alert. For a Sonner-shaped API, see Sonner.

Scroll to load preview...

Usage

import { toast } from "@/components/ui/toast"
toast.add({
  title: "Event created",
  description: "Sunday, December 3 at 9:00 AM",
})

Mount <Toaster /> once in the root layout. toast.add returns an id — pass it to toast.close.

Composition

Toast
ToastContent
ToastTitle
ToastDescription
ToastAction
ToastClose

Types

type is success, info, warning, error, or loading. Each one paints an icon.

Scroll to load preview...

Action

actionProps is a button. Use it for Undo. Close the toast from onClick.

const id = toast.add({
  title: "Event created",
  actionProps: {
    children: "Undo",
    onClick() {
      toast.close(id)
    },
  },
})

Promise

toast.promise updates one toast as a task moves through loading, success, and error.

Scroll to load preview...

API

Prop

Type

toast.add(options) returns an id. toast.close(id) dismisses it. toast.promise(promise, options) wires loading / success / error.

Keyboard

KeyAction
TabFocus the action or close button
EscapeDismiss the focused toast
Space / EnterActivate the action

Notes

Toaster once

Put <Toaster /> in the root layout. A second provider means toast.add talks to the wrong stack and nothing appears.

Don't fire a toast for something they already see on the page. That's noise.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.