Guide
Loading toasts that turn into success or error
A loading toast should become the result, not sit next to it. Wrap the work in toast.promise, or start with toast.loading and call toast.update with the same id, and one toast goes from loading to success or error.
The short way: toast.promise
toast.promise shows a loading toast, waits, then changes it into a success or an error. It takes a promise or a function that returns one.
It returns your promise, so you get the value back and rejections still reach your code. Handle them as you would without the toast.
More control: toast.loading and toast.update
When the result needs a description, a button or a different type than plain success or error, keep the id and update it yourself:
Changing the type resets the timer to that type’s usual length: the success closes after 5 seconds, the error stays until dismissed. See update a toast.
How do I show progress in a toast?
Pass progress as a number from 0 to 1. A thin bar along the bottom edge fills as you update it, and progress: null removes it.
Progress updates are not read out by screen readers, even when they carry a new description, so you can update as often as you like without flooding them. The final type change is announced.
How long does a loading toast stay?
Until you update or dismiss it. A loading toast has no timer, so it will not vanish halfway through a slow request. That also means a forgotten update leaves it spinning, so make sure every path of your code ends in toast.update or toast.dismiss(id).
Frequently asked questions
When does a loading toast go away?
No. Loading toasts stay until you update them to another type or dismiss them. Once updated to success, the 5 second timer starts.
What happens if the promise rejects?
The toast becomes an error with your error message, and toast.promise returns the rejected promise so your code can handle it too.
Can the success message use the result?
Yes. Pass a function as success and it receives the resolved value. error can be a function of the error in the same way.
Are progress updates announced to screen readers?
No. Progress changes stay quiet so frequent updates do not interrupt. A change of type is announced, and so is a new title or description sent without a progress value.
Related guides
- React toast notificationsOne component and one function call.
- Undo toastAct first, offer undo.
- React toast animationSprings, morphing in place and reduced motion.
- Boing docsSetup, options, styling, sound and accessibility.