A toast is a short message on a surface card that hides itself after six seconds. Wrap the app in ToastProvider, then call addToast({ variant, message }) from useToast anywhere under it, as on the web. See the web Toast for the same component in the browser.
Put ToastProvider inside ThemeProvider, around the rest of the app. It draws the toasts above everything in it, stacked at the bottom of the screen with the newest last.
variant sets the icon: success, danger, warning or info. Each toast has a close button.
action adds an element before the close button, such as an undo button. duration is in milliseconds; Infinity keeps the toast until it is closed.
Toast also renders on its own, where you place it. It hides itself after duration and calls onClose. Without onClose it has no close button.
- useToast throws outside a ToastProvider.
- Toasts sit above the home indicator when the safe-area insets are passed to ThemeProvider, as shown on the overview.
- A danger toast is announced right away; the others wait for the screen reader to finish.