Toast
Imperative notification system. Call toast() from anywhere in your app —
no prop drilling required. Messages stack in the top-right corner and auto-dismiss after
4 seconds.
Setup
React: wrap your app root with ToastProvider once.
Vue: place ToastViewport once in your app root or layout component.
Usage
Call useToast() inside any component to get the toast() function.
Variants & options
toast({ title: "Saved", variant: "success" });
toast({ title: "Heads up", variant: "warning" });
toast({ title: "Something failed", variant: "danger" });
toast({ title: "FYI", variant: "default" });
// With description
toast({
title: "Deployment complete",
description: "v1.2.0 is now live.",
variant: "success",
});
// Stays until dismissed
toast({ title: "Processing…", duration: Infinity }); // same API — useToast() returns { toast, dismiss }
toast({ title: "Saved", variant: "success" });
toast({ title: "Heads up", variant: "warning" });
toast({ title: "Something failed", variant: "danger" });
toast({
title: "Deployment complete",
description: "v1.2.0 is now live.",
variant: "success",
}); toast() options
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | — | Primary message shown in bold. |
description | string | — | Secondary detail text below the title. |
variant | "default" | "success" | "warning" | "danger" | "default" | Colour style. |
duration | number | 4000 | Auto-dismiss delay in ms. Pass Infinity to keep until dismissed. |
Valid props
| Prop | Values | Default |
|---|---|---|
variant | "default"|"success"|"warning"|"danger" | default |
Common AI mistakes
- Rendering <Toast> directly in JSX→ Use: const { toast } = useToast(); then toast({ title, variant })
- variant="error"→ Use variant="danger"
- variant="info"→ Use variant="default"
Quick examples
Trigger a success toast
const { toast } = useToast();
<Button onClick={() => toast({ title: 'Saved!', variant: 'success', duration: 3000 })}>
Save
</Button>Setup: wrap app with ToastProvider
<ToastProvider>
<App />
</ToastProvider>