Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Sonner examples · Content

Toast with Custom Duration Sonner for React

A toast that stays on screen for 10 seconds instead of the default 4.

Framework
UI library

Four seconds is too short for a message people need to read. This toast passes duration: 10_000 on the call, so it stays for 10 seconds while other toasts keep the default.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How long does this toast stay?

The call passes duration: 10_000 with the message "This toast will stay for 10 seconds". The number is milliseconds, so this notice stays for 10 seconds.

What is the lifetime when I omit duration?

A toast with no duration uses duration on Toaster, or 4 seconds when Toaster omits it too. This call sets the time on this toast only.

Can the user close it before 10 seconds?

Yes. This call omits dismissible, so a swipe can still close it. The timer only sets the auto-close.

Does this duration apply to every toast?

No. duration on the call is for this notice. Set duration on Toaster when every toast should share one lifetime.

Does the message set the time?

No. The sentence is only the title, and the 10 seconds come from the duration option. This call passes no description or action.

Does the demo render the toaster?

The demo renders its own Toaster beside the button, so it works on its own. In an app, render one Toaster near the root and call toast from anywhere.