Skip to content

useToast

Access Sonner toast notifications.

Signature

ts
function useToast(): { toast: typeof toast; dismiss: typeof toast.dismiss }

Return Type

PropertyTypeDescription
toasttoastSonner toast function
dismisstoast.dismissDismiss 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!')

See also