create site with shadcn sonner toast
Let's build a Next.js application that demonstrates the Sonner toast component from shadcn/ui 1.
This demo showcases the Sonner toast component from shadcn/ui with various configurations:
Toaster
component is added to the root layout to make toasts available throughout the application 1.Toast Types:
Advanced Features:
To use the toast functionality in your components:
import { toast } from "sonner"
// Basic toast
toast("Hello world!")
// Success toast
toast.success("Operation completed successfully")
// Error toast
toast.error("Something went wrong")
// Promise toast
toast.promise(fetchData(), {
loading: "Loading...",
success: "Data loaded successfully",
error: "Failed to load data"
})
You can customize the appearance, position, duration, and add actions to your toasts as shown in the demo.