shadcn.io is not affiliated with official shadcn/ui
Sonner examples · Interactive
Toast with Action Button Sonner for React
A toast with an Undo action button that confirms with a second toast.
An action button lets people react without leaving the toast, the classic case being Undo. This toast passes action with a label and an onClick; clicking Undo closes it and shows a success toast.
Preview
Installation
FAQ
How is the Undo button set?
The toast title is "Event has been created". action is { label: "Undo", onClick: () => toast.success("Action clicked") }. The label is the button text.
What happens when Undo is clicked?
onClick runs, then the toast closes. This handler does not call preventDefault, so the close still happens, and a success toast shows "Action clicked".
How do I add a second button?
Pass cancel with its own label and onClick. This demo passes action only, so there is one button.
Which other options does this call pass?
None. There is no description, duration, icon, or position. The notice is the title plus the Undo action.
Related
- Toast with Cancel Button SonnerA toast with a Cancel button that closes
- Toast with Action and Cancel SonnerA toast with a Delete action and a Cancel
- Default Toast SonnerA button that shows a plain toast with
- Standard with Title AlertA neutral alert with only a title, for a
- Non-Dismissible Toast SonnerA toast that can't be swiped away and
- Toast with Custom Duration SonnerA toast that stays on screen for 10