A notification that appears temporarily to provide feedback on an action or event.

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

export default function ToastDemo() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.add({
          title: "Event has been created",
          description: "Monday, January 3rd at 6:00pm",
        })
      }
    >
      Show Toast
    </Button>
  );
}

Installation

Usage

Add ToastProvider once at the root of your app, then use toastManager to trigger toasts from anywhere.

import { ToastProvider } from "@/components/ui/toast";
 
export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <ToastProvider>{children}</ToastProvider>
      </body>
    </html>
  );
}
import { toastManager } from "@/components/ui/toast";
 
toastManager.add({
  title: "Event has been created",
  description: "Monday, January 3rd at 6:00pm",
});

Examples

Success

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

export default function ToastSuccess() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.add({
          type: "success",
          title: "Changes saved",
          description: "Your changes have been saved.",
        })
      }
    >
      Show Toast
    </Button>
  );
}

Warning

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

export default function ToastWarning() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.add({
          type: "warning",
          title: "Storage almost full",
          description: "You are using 90% of your storage.",
        })
      }
    >
      Show Toast
    </Button>
  );
}

Info

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

export default function ToastInfo() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.add({
          type: "info",
          title: "Update available",
          description: "A new version is ready to install.",
        })
      }
    >
      Show Toast
    </Button>
  );
}

Destructive

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

export default function ToastDestructive() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.add({
          type: "destructive",
          title: "Something went wrong",
          description: "Your request could not be processed.",
        })
      }
    >
      Show Toast
    </Button>
  );
}

Loading

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

export default function ToastLoading() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.add({
          type: "loading",
          title: "Uploading file",
          description: "Please wait this will take some time.",
        })
      }
    >
      Show Toast
    </Button>
  );
}

Promise

"use client";

import { Button } from "@/components/ui/button";
import { toastManager } from "@/components/ui/toast";

function fakeUpload() {
  return new Promise<{ name: string }>((resolve) =>
    setTimeout(() => resolve({ name: "report.pdf" }), 2000),
  );
}

export default function ToastPromise() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toastManager.promise(fakeUpload(), {
          loading: { title: "Uploading..." },
          success: (data) => ({
            title: "Upload complete",
            description: `${data.name} was uploaded successfully.`,
          }),
          error: { title: "Upload failed", description: "Please try again." },
        })
      }
    >
      Show Toast
    </Button>
  );
}