API
Full method and options reference for the core package. Nothing is required beyond importing. CSS is included from the package entry. The portal auto-mounts.
Required setup
import { toast } from "alert-notify";
toast.success("Hello");Methods
| Method | Returns | Description |
|---|---|---|
toast(message, options?) | ToastId | Generic toast (message type). Message may be string | undefined |
toast.success(message, options?) | ToastId | Success toast |
toast.error(message, options?) | ToastId | Error toast |
toast.warning(message, options?) | ToastId | Warning toast |
toast.info(message, options?) | ToastId | Info toast |
toast.loading(message, options?) | ToastId | Loading toast (autoClose: false by default) |
toast.message(message, options?) | ToastId | Neutral message toast |
toast.custom(content, options?) | ToastId | Custom HTML string or HTMLElement |
toast.promise(promise, messages) | Promise<T> | Loading → success/error on same id |
toast.dismiss(id?) | void | Dismiss one toast, or all if omitted |
toast.isActive(id) | boolean | Whether that toast id is still open |
toast.config(partial) | void | Update global toaster defaults |
toast.getConfig() | ToasterConfig | Read current global config |
toast.getToasts() | ToastRecord[] | Current toast list (headless) |
toast.subscribe(listener) | () => void | Subscribe to toast list changes |
toast.destroy() | void | Dismiss all + remove portal |
createToaster(config?, options?) | ToasterInstance | Isolated toaster (multi-instance) |
Per-toast options
| Option | Type | Default | Description |
|---|---|---|---|
id | string | auto UUID | Stable id. Same id updates in place |
type | ToastType | from method | success | error | warning | info | loading | message |
title | string | - | Optional heading |
duration | number | from config | Ms until auto-close when autoClose is true |
autoClose | boolean | true (false for loading) | Whether the toast auto-dismisses |
icon | string | HTMLElement | false | built-in SVG | Custom icon HTML/node, or false to hide. Framework entries also accept framework nodes |
action | { label, onClick } | - | Primary action button |
cancel | { label, onClick } | - | Secondary cancel button |
closeButton | boolean | from config | Show × button |
dismissible | boolean | from config | Allow swipe / close dismiss |
important | boolean | false | Jump to front of the queue |
position | ToastPosition | from config | Override stack corner for this toast |
richColors | boolean | from config | Override tinted surface for this toast |
className | string | - | Extra class on the toast element |
style | object | - | Inline styles on the toast |
onOpen | (toast) => void | - | Fired once when the toast is first created |
onClose | (toast, reason) => void | - | Fired once; reason is "Manual" or "Auto" |
Promise API
toast.promise(uploadFile(), {
loading: "Uploading…",
success: (file) => `Uploaded ${file.name}`,
error: (err) => (err instanceof Error ? err.message : "Failed"),
});Multiple toasters and headless
import { createToaster } from "alert-notify";
const modalToast = createToaster({ position: "bottom-center" });
modalToast.success("Saved in modal");
const headless = createToaster({}, { headless: true });
headless.subscribe((toasts) => {
// render custom UI from toasts[]
});Behavior notes
- Title and message are HTML-escaped by default. Use
toast.custom()for trusted markup. loadingtoasts default to sticky until updated (for example via promise).- Same
idcoalesces instead of stacking a duplicate.onOpendoes not re-fire on coalesce. - Per-toast
positionuses a separate stack from the default corner. - Per-toast
richColorsoverrides the toaster default for that toast only. - Escape dismisses the focused toast. Swipe dismisses when
dismissibleis true. - SSR-safe: no DOM work until
documentexists.
Also see Config.