shadcn.io is not affiliated with official shadcn/ui
Sonner examples · Promise
Loading Toast Sonner for React
A loading toast with a spinner that stays until you dismiss or update it.
toast.loading shows a spinner and a message, and doesn't close on its own. Use it when you control the task yourself and will update or dismiss the toast when it's done; toast.promise does that for you.
Preview
Installation
FAQ
What does this loading toast pass?
The button calls toast.loading with "Processing your request...". That sets the type to loading. Toaster shows a spinning Loader2Icon with className="size-4 animate-spin".
Does this loading toast close on its own?
No. A toast whose type is loading skips the auto-close timer. This call does not pass duration, and the file never dismisses it, so the spinner stays up.
How do I clear it when the request finishes?
toast.loading returns an id. This demo ignores that id. Keep it, then pass the same id to toast.success or toast.error to reuse the toast, or pass it to toast.dismiss.
How do I let the toast swap to success or error for me?
Call toast.promise with the promise and loading, success, and error messages. That keeps one toast and replaces the loading line when the promise settles. This demo calls toast.loading only.
Related
- Basic Promise Toast SonnerA promise toast that shows Loading
- Promise Toast with Data SonnerA promise toast whose success message
- Non-Dismissible Toast SonnerA toast that can't be swiped away and
- Default SpinnerA spinner at its default size and color
- Article Preview SkeletonAn article preview placeholder with an
- Promise Toast with Error SonnerA promise toast that fails after 2