next-toastv1.0.6
Documentation

Examples

Small patterns for common product interactions.

Save with promise states

Save profile
const profile = await toast.promise(saveProfile(), {
  loading: "Saving profile…",
  success: "Profile saved",
  error: (error) =>
    error instanceof Error ? error.message : "Could not save",
});

Undo a destructive action

Archive with Undo
toast.info("Draft archived", {
  action: {
    label: "Undo",
    onClick: restoreDraft,
  },
});

Confirm deletion

Delete project
toast.confirm(
  "Delete this project? This cannot be undone.",
  deleteProject,
  { label: "Delete", cancelLabel: "Keep project" },
);

Update a loading toast

Upload progress
const id = toast.loading("Uploading file…");

try {
  await uploadFile();
  toast.update(id, {
    type: "success",
    message: "Upload complete",
    duration: 3000,
    dismissible: true,
  });
} catch {
  toast.update(id, {
    type: "error",
    message: "Upload failed",
    dismissible: true,
  });
}

Prevent duplicate toasts

Reuse an id to replace the existing toast instead of adding another.

Stable id
toast.info("Syncing…", { id: "project-sync" });

toast.success("Sync complete", { id: "project-sync" });

Custom content

Custom React content
toast.custom((item) => (
  <div className="rounded-lg border bg-card p-4">
    New message
    <button onClick={() => toast.dismiss(item.id)}>Close</button>
  </div>
), { duration: 5000 });