Toast Provider
Manage independent notifications, expiry and dismissal.
Usage
Mount ToastProvider once for a product surface, then call showToast from useToast after a real result. A full visible stack queues new notifications until space is available.
Accessibility
Show confirmations politely and errors as alerts, without moving focus on arrival. Expiry pauses during hover or focus. Dismissal restores focus to a remaining notification or the original control.
| Property | Type | Default |
|---|---|---|
| maxVisible | number | 4 |
| dismissLabel | string | Dismiss notification |
| showToast(options) | ToastNotification → string | Required title |
| dismissToast(id) | string → void | None |
| duration (notification) | number | null | 3000; important states persist |
const Controls = () => {
const { showToast } = useToast();
return (
<div>
<Button onClick={() => showToast({ title: 'Project saved', description: 'Your changes are ready.', tone: 'success' })}>
Show saved notification
</Button>
<Button variant="secondary" onClick={() => showToast({ title: 'Save failed', description: 'Your changes could not be synchronized. Check your network connection and retry when you are ready.', tone: 'error' })}>
Show error notification
</Button>
</div>
);
};
<ToastProvider maxVisible={2}>
<Controls />
</ToastProvider>