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

MethodReturnsDescription
toast(message, options?)ToastIdGeneric toast (message type). Message may be string | undefined
toast.success(message, options?)ToastIdSuccess toast
toast.error(message, options?)ToastIdError toast
toast.warning(message, options?)ToastIdWarning toast
toast.info(message, options?)ToastIdInfo toast
toast.loading(message, options?)ToastIdLoading toast (autoClose: false by default)
toast.message(message, options?)ToastIdNeutral message toast
toast.custom(content, options?)ToastIdCustom HTML string or HTMLElement
toast.promise(promise, messages)Promise<T>Loading → success/error on same id
toast.dismiss(id?)voidDismiss one toast, or all if omitted
toast.isActive(id)booleanWhether that toast id is still open
toast.config(partial)voidUpdate global toaster defaults
toast.getConfig()ToasterConfigRead current global config
toast.getToasts()ToastRecord[]Current toast list (headless)
toast.subscribe(listener)() => voidSubscribe to toast list changes
toast.destroy()voidDismiss all + remove portal
createToaster(config?, options?)ToasterInstanceIsolated toaster (multi-instance)

Per-toast options

OptionTypeDefaultDescription
idstringauto UUIDStable id. Same id updates in place
typeToastTypefrom methodsuccess | error | warning | info | loading | message
titlestring-Optional heading
durationnumberfrom configMs until auto-close when autoClose is true
autoClosebooleantrue (false for loading)Whether the toast auto-dismisses
iconstring | HTMLElement | falsebuilt-in SVGCustom 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
closeButtonbooleanfrom configShow × button
dismissiblebooleanfrom configAllow swipe / close dismiss
importantbooleanfalseJump to front of the queue
positionToastPositionfrom configOverride stack corner for this toast
richColorsbooleanfrom configOverride tinted surface for this toast
classNamestring-Extra class on the toast element
styleobject-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

Also see Config.