The ToastProvider wraps your app to provide access to useToast, allowing any component to trigger lightweight, dismissible toast messages globally.
Wrap your app with ToastProvider to activate toast functionality.
We recommend using a Providers component to wrap your app. You can choose to display toasts at the top or bottom based on breakpoints.
Use the useToast() hook to display notifications from anywhere in your app:
addToast returns the new toast's id. Pass it to removeToast to take the toast down before it times out, such as a "Saving…" toast once the save is done. Each toast stays up for its duration in milliseconds: 6000 by default, and Infinity keeps it up until it is closed. The countdown pauses while the toast is hovered or has focus, and resumes with the time that was left.
addToast and removeToast keep the same identity for the provider's lifetime, so an effect can list them as dependencies without running again each time a toast appears. There is no need to hold them in a ref.
The ToastProvider automatically renders a <Toaster /> under the hood, passing it the current list of toasts and a removeToast handler.