apps/v4/content/docs/components/radix/sonner.mdx
Sonner is built and maintained by emilkowalski.
<Step>Run the following command:</Step>
npx shadcn@latest add sonner
<Step>Add the Toaster component</Step>
import { Toaster } from "@/components/ui/sonner"
export default function RootLayout({ children }) {
return (
<html lang="en">
<head />
<body>
<main>{children}</main>
<Toaster />
</body>
</html>
)
}
<Step>Install the following dependencies:</Step>
npm install sonner next-themes
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="sonner" title="components/ui/sonner.tsx" styleName="radix-nova" />
<Step>Add the Toaster component</Step>
import { Toaster } from "@/components/ui/sonner"
export default function RootLayout({ children }) {
return (
<html lang="en">
<head />
<body>
<Toaster />
<main>{children}</main>
</body>
</html>
)
}
import { toast } from "sonner"
toast("Event has been created.")
Use the position prop to change the position of the toast.
See the Sonner API Reference for more information.