Toast API
A small set of methods covers simple messages and complete interaction flows.
Basic methods
| Method | Use for |
|---|---|
| toast.message | Neutral feedback |
| toast.success | Completed action |
| toast.error | Failed action |
| toast.warning | Recoverable issue |
| toast.info | Informational update |
| toast.loading | Pending operation |
Basic toasts
toast.message("Document saved");
toast.success("Changes saved");
toast.error("Could not save");
toast.warning("You have unsaved changes");
toast.info("A new version is available");Toast options
Pass options as the second argument to any standard method. Use duration: Infinity for a persistent toast. Reusing an id replaces the existing toast.
| Option | Type | Default |
|---|---|---|
| id | string | number | generated |
| description | ReactNode | — |
| duration | number | 4000 ms |
| dismissible | boolean | true |
| action | { label, onClick } | — |
Options
toast.info("Sync started", {
description: "This may take a few minutes.",
duration: 6000,
dismissible: true,
});Actions
Add one short action for undo, retry, or view flows.
Undo action
toast.error("File deleted", {
action: {
label: "Undo",
onClick: restoreFile,
},
});Loading and update
toast.loading returns an id. Update that toast when the operation finishes.
Loading state
const id = toast.loading("Uploading…");
toast.update(id, {
type: "success",
message: "Upload complete",
duration: 3000,
dismissible: true,
});Promise states
The original result is returned, and rejected promises are rethrown.
toast.promise
const user = await toast.promise(saveUser(), {
loading: "Saving user…",
success: (saved) => `Saved ${saved.name}`,
error: "Could not save user",
});Confirmation
Use a confirmation toast for compact decisions that do not need a modal.
Confirm delete
toast.confirm("Delete this project?", deleteProject, {
label: "Delete",
cancelLabel: "Keep project",
});Custom content
Render any React content when the standard layout is not enough.
Custom toast
toast.custom((item) => (
<div className="rounded-lg border bg-card p-4">
Custom content
<button onClick={() => toast.dismiss(item.id)}>Close</button>
</div>
), { duration: 5000 });Dismiss
Dismiss one toast by id, or omit the id to clear the stack.
Dismiss toasts
toast.dismiss(id);
toast.dismiss(); // Dismiss every toastTypeScript
Public configuration and toast types are exported with the API.
Type imports
import {
toast,
type ToastConfig,
type ToastOptions,
type ToastT,
} from "next-toast";Renderer settings live in Configuration.