Docs
Toast

Toast

A succinct message that is displayed temporarily.

Installation

Run the following command:

pnpm dlx shadcn@latest add toast

Add the Toaster component

app/layout.tsx
import { Toaster } from "@/components/ui/toaster"
 
export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head />
      <body>
        <main>{children}</main>
        <Toaster />
      </body>
    </html>
  )
}

Usage

The useToast hook returns a toast function that you can use to display a toast.

import { useToast } from "@/hooks/use-toast"
export const ToastDemo = () => {
  const { toast } = useToast()
 
  return (
    <Button
      onClick={() => {
        toast({
          title: "Scheduled: Catch up",
          description: "Friday, February 10, 2023 at 5:57 PM",
        })
      }}
    >
      Show Toast
    </Button>
  )
}

Examples

Simple

With title

With Action

Destructive

Use toast({ variant: "destructive" }) to display a destructive toast.