Usage
Hook for showing toast notifications from anywhere in your component tree; it needs no provider or mounted ToastViewport: inside LayerProvider (or a ToastViewport) it uses that viewport, and otherwise the first toast mounts a fallback viewport on document.body with a development warning. Returns the show function itself (not an object): const showToast = useToast(); call it with toast options to show the notification.
tsimport {useToast} from '@astryxdesign/core/Toast'
Best practices
| Guidance | Practices |
|---|---|
| Do | Use for transient success/error feedback that does not require user action. |
| Do | Set uniqueID to deduplicate toasts from rapid user actions. |
| Do | For an undo action, pass endContent: <Button label="Undo" variant="ghost" onClick={...} />, and call the dismiss function that showToast returns from that onClick. |
| Don't | Use for critical errors that require acknowledgment; use AlertDialog instead. |
| Don't | Call useToast in the same component that renders LayerProvider; it must be called from a child component inside the provider. |
Returns
| Field | Type | Description |
|---|---|---|
| value | (options: ) => () => void | useToast returns the show function itself, not an object: |
Examples
Common configurations, variations, and states.Imperative toast notifications triggered with useToast and rendered in the toast viewport.
Shows a toast from the function useToast returns: a "Settings saved" confirmation with an Undo action, a uniqueID so pressing the button again replaces the toast instead of stacking another, and an error toast when the request fails.
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-5m4jhlnok-fbopensource.vercel.app/shadcn/hooks/use-toast.json