Appearance
useToast
Access Sonner toast notifications.
Signature
ts
function useToast(): { toast: typeof toast; dismiss: typeof toast.dismiss }Return Type
| Property | Type | Description |
|---|---|---|
toast | toast | Sonner toast function |
dismiss | toast.dismiss | Dismiss toast function |
Toast Methods
ts
toast(message) // Default toast
toast.success(message) // Success toast
toast.error(message) // Error toast
toast.warning(message) // Warning toast
toast.info(message) // Info toast
toast.loading(message) // Loading toast
toast.promise(promise, options) // Promise toast
toast.dismiss(id?) // Dismiss toast(s)Example
tsx
const { toast } = useToast()
// Simple
toast.success('Saved!')
// With options
toast.error('Failed to save', {
description: 'Please try again',
duration: 5000,
})
// Promise
toast.promise(saveData(), {
loading: 'Saving...',
success: 'Saved!',
error: 'Failed to save',
})Direct Import
You can also import toast directly:
tsx
import { toast } from '@/shared/hooks/useToast'
toast.success('Done!')