Published on

Sonner - Shadcn component

Authors
  • avatar
    Name
    Shelton Ma
    Twitter
  1. Add npx shadcn@latest add sonner

  2. Enable in global

    // src/app/layout.tsx
    import { Toaster } from "@/components/ui/sonner";
    ...
    <body
      className={`${geistSans.variable} ${geistMono.variable} antialiased`}
    >
      <Providers>
        <Toaster />
        <Modals />
        {children}
      </Providers>
    </body>
    ...
    
  3. Use in component

    import { toast } from "sonner";
    ... 
    const handleSubmit = () => {
      ...
      toast.success("Workspace created");
      toast.error("Something went wrong");
    };