next-toastv1.0.6
Documentation

Toast API

A small set of methods covers simple messages and complete interaction flows.

Basic methods

MethodUse for
toast.messageNeutral feedback
toast.successCompleted action
toast.errorFailed action
toast.warningRecoverable issue
toast.infoInformational update
toast.loadingPending 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.

OptionTypeDefault
idstring | numbergenerated
descriptionReactNode—
durationnumber4000 ms
dismissiblebooleantrue
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 toast

TypeScript

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.