useToast
Raise a toast from anywhere under a Toaster: a message, a type, an Undo action.
import { useToast, Toaster } from "@forgeron/ui";// A toast raised from a handler: a plain message, a success, and an Undo that raises another.
import { Button, Toaster, useToast } from "@forgeron/ui";
function Actions() {
const toast = useToast();
return (
<>
<Button
onClick={() =>
toast.add({
title: "OPS-40 deleted",
actionProps: {
children: "Undo",
onClick: () => toast.add({ title: "OPS-40 restored" }),
},
})
}
>
Delete issue
</Button>
<Button onClick={() => toast.add({ title: "crm 1.4.0 is live", type: "success" })}>
Deploy
</Button>
</>
);
}
export default function Undo() {
return (
<Toaster>
<Actions />
</Toaster>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
add(options) | { title, description?, type?, actionProps? } | — | type is “success” or “danger”; actionProps: { children: “Undo”, onClick } adds a button. Returns the toast id. |
close(id) | (id) => void | — | Dismisses a toast. |
returns | { toasts, add, close, update, promise } | — | The toast manager. Needs a Toaster above it; Toaster limit defaults to 3. |