Callbacks & haptics
React to presses, dismissals, and timeouts, and add haptic feedback.
Callbacks
toast('Draft saved', {
onPress: () => openDrafts(),
onDismiss: (id) => console.log('dismissed', id),
onAutoClose: (id) => console.log('timed out', id),
});| Callback | Called when |
|---|---|
onPress | The toast body is pressed. |
onDismiss | The toast is swiped away, closed, cancelled, or dismissed with toast.dismiss. |
onAutoClose | The toast's duration elapses. |
action.onClick | The action button is pressed. The toast is then dismissed. |
cancel.onClick | The cancel button is pressed, before onDismiss. |
Each dismissal callback runs at most once per toast.
Haptics
Play a light haptic when a toast appears or updates.
<ToastHost haptic />;
toast.success('Paid', { haptic: true });iOS uses UIImpactFeedbackGenerator; Android uses the window's haptic feedback.