Skip to content

useToast

useToast(): ToastApi

Defined in: packages/ui/src/hooks/use-toast.ts:40

Returns an imperative ToastApi for showing toast notifications.

Provides convenience methods (success, error, info, warning) as well as a generic show method that accepts full ToastOptions.

Must be used within a ToastProvider — typically supplied by the Joy UI plugin (backed by Sonner) or a custom UI plugin implementation.

ToastApi

A ToastApi object with methods for each notification type.

If called outside of a ToastProvider.

function PublishButton() {
const toast = useToast();
async function handlePublish() {
try {
await publishPost();
toast.success("Post published");
} catch (err) {
toast.error("Failed to publish post");
}
}
return <button onClick={handlePublish}>Publish</button>;
}