Skip to main content

API Reference

ToasterProvider Props​

Provider Configuration

Wrap your app with ToasterProvider at the root level to ensure toast functionality is available throughout your application. This enables you to use the useToast hook in any nested component.

Memory Management

Avoid creating new function references for onToastDismiss prop on each render. Use useCallback for event handlers to prevent unnecessary re-renders.

PropTypeDefaultDescription
positionnumber80Position where toasts will appear from top
durationnumber3000Default duration (in ms) for toasts to remain visible
offsetnumber16Distance from the edge of the screen
backgroundColorstring"#333333"Default background color for toasts
textColorstring"#FFFFFF"Default text color for toasts
successColorstring"#4CAF50"Background color for success toasts
errorColorstring"#F44336"Background color for error toasts
infoColorstring"#2196F3"Background color for info toasts
warningColorstring"#FF9800"Background color for warning toasts
animationDurationnumber300Duration of show/hide animations
onToastDismiss(id: string) => void-Callback when a toast is dismissed
childrenReactNode-The content to be wrapped by ToasterProvider

useToast Hook​

Performance Optimization

Use the useToast hook at the component level where you need toast functionality. Destructure only the methods you need to minimize unnecessary re-renders.

State Management

Do not call show methods during render. Use event handlers or effects to trigger toasts.

The useToast hook provides methods to display and control toasts. Here's a detailed reference of the returned object:

Method/PropertyTypeDescription
showToast(message: string, options?: ToastOptions) => stringShows a basic toast with default styling
hideToast(id: string) => voidManually hides a specific toast by its ID

ToastOptions​

OptionTypeDescription
durationnumberTime in ms the toast should remain visible
backgroundColorstringCustom background color for this toast
textColorstringCustom text color for this toast