Guide
Toast notifications in the Next.js App Router
In the Next.js App Router, render <Toaster /> from react-boing in app/layout.tsx and call toast from client components. The package is already marked "use client", so the server layout can render it without a wrapper.
Add the Toaster to the root layout
The Toaster does not touch the DOM while rendering, so it works in static, dynamic and streamed routes. Because it lives in the root layout, a toast shown on one page stays on screen through client-side navigation to the next.
Call toast from a client component
Toasts happen in the browser, so toast is called from client code, usually an event handler in a file that starts with 'use client':
Calling toast inside a server component or a server action does nothing useful: that code runs on the server, where there is no Toaster to show it.
How do I show a toast after a server action?
Have the action return a result object, then turn that result into a toast in the client component that called it.
If you want a loading state while the action runs, start with toast.loading and pass the id to toast.update once the result arrives. For an action that throws instead of returning an error, toast.promise(renameProject(formData), { … }) covers all three steps.
Pass a CSP nonce
The Toaster adds one <style> element to <head>. If your Content Security Policy only allows inline styles with a nonce, read the nonce in the layout and pass it on. This example assumes your middleware or proxy puts it in an x-nonce request header:
Reading headers makes the layout render per request, which a nonce needs anyway. If the nonce is wrong and the styles are blocked, icons keep their own small width and height. More in the docs.
Frequently asked questions
Do I need a client wrapper component for the Toaster in Next.js?
No. The published files start with a "use client" directive, so app/layout.tsx can import and render <Toaster /> directly.
Can a server action show a toast by itself?
No. A server action runs on the server. Return a result from it and call toast.success or toast.error in the client component that awaited it.
Does the toast survive client-side navigation?
Yes, when the Toaster is in the root layout. Layouts stay mounted across navigations, so the visible toast keeps its place and its timer.
Does it work with the Pages Router?
Yes. Render <Toaster /> in pages/_app.tsx and call toast from your components the same way.
Related guides
- React toast notificationsOne component and one function call.
- shadcn/ui toastFits the shadcn look out of the box.
- Loading toastOne toast from loading to done.
- Boing docsSetup, options, styling, sound and accessibility.