toast('Saved'). From a store, a loader, anywhere.
Mount one <Toaster />, then call toast() from components, stores, route loaders or a plain fetch wrapper. No provider, no hook, no context. Promise toasts, actions, a countdown that waits while the user reads, and the right screen-reader role for each type come with it.
bun add @pyreon/toast - setup
- one
<Toaster />Thentoast()from any module. - vs react-hot-toast
- cold create 3.3× faster2.5× vs sonner. One run, bun/JavaScriptCore.
- screen readers
role="alert"for errorsrole="status"for info and success.- iOS and Android
-
toast()+<Toaster>Experimental. A native overlay in the next release; promise, update and JSX content stay web.
- 3.3× faster cold toast creation than react-hot-toast (2.5× vs sonner)BENCHMARKS.md §10, toast row · overnight run, one run, bun/JavaScriptCore
- 2.5–3.8× faster headless store operations than react-hot-toastBENCHMARKS.md §10, toast row · one run
- 3 independent pauses: hover, keyboard focus, hidden tabpackages/fundamentals/toast/src/toast.ts pause sources; .agents/guides/fundamentals/references/toast.md
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →The toast system you keep rebuilding, finished.
Call it where the error happens
A store action, a route loader or an HTTP interceptor can call
toast.error('Card declined')directly. Error handling stays next to the error, not threaded through a hook.Loading to done in one call
toast.promise(upload(), { loading: 'Uploading…', success: (n) =>Uploaded ${n} files, error: 'Upload failed' })swaps the same toast in place and returns your promise.A countdown that waits for the reader
Hovering, tabbing into a toast, or switching tabs each hold the timer. The holds are tracked separately, so releasing one does not restart the clock while another still holds it.
Announced with the right urgency
Errors and warnings use
role="alert", info and successrole="status", each witharia-atomic. The container sets noaria-live, so nothing is read twice.
You wrote this provider. It never paused on hover.
A context, an array in state, a timer per toast. No pause, no screen-reader role, and no way to call it from outside a component.
const ToastContext = createContext<(msg: string) => void>(() => {})
export function ToastProvider({ children }: { children: ReactNode }) {
const [toasts, setToasts] = useState<{ id: number; msg: string }[]>([])
const show = useCallback((msg: string) => {
const id = Date.now()
setToasts((t) => [...t, { id, msg }])
setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), 4000)
}, [])
return (
<ToastContext.Provider value={show}>
{children}
<div className="toasts">
{toasts.map((t) => <div key={t.id}>{t.msg}</div>)}
</div>
</ToastContext.Provider>
)
}Mount once. Call from anywhere. Pausing, roles, animation and cleanup are done.
import { toast, Toaster } from '@pyreon/toast'
const App = () => (
<>
<Toaster position="top-right" />
<Routes />
</>
)
// in a store, a loader, a fetch wrapper:
toast.success('Saved')Coming from sonner or react-hot-toast?
The calls you know, no React.
import { Toaster, toast } from 'sonner'
toast.promise(save(), {
loading: 'Saving…',
success: 'Saved',
error: 'Could not save',
})
toast.error('Card declined', {
description: 'Try another card',
action: { label: 'Retry', onClick: () => retry() },
})
// once, at the root of the app
<Toaster position="top-right" />Same shapes for promise, description and action. sonner's collapsed stack and swipe-to-dismiss are not here; toasts list up to max (5 by default).
import { Toaster, toast } from '@pyreon/toast'
toast.promise(save(), {
loading: 'Saving…',
success: 'Saved',
error: 'Could not save',
})
toast.error('Card declined', {
description: 'Try another card',
action: { label: 'Retry', onClick: () => retry() },
})
// once, at the root of the app
<Toaster position="top-right" />loading, then the same id.
import toast from 'react-hot-toast'
const id = toast.loading('Uploading…')
// later
toast.success('Uploaded', { id })The same split as react-hot-toast: toast.dismiss(id) plays the leave animation, toast.remove(id) removes at once.
import { toast } from '@pyreon/toast'
const id = toast.loading('Uploading…')
// later
toast.update(id, { type: 'success', message: 'Uploaded', duration: 4000 })Make some toast.
Hover the stack to pause every countdown. The demo's Toaster has max={3}: fire more and the newest three stay on screen while older ones wait behind them, coming back when a newer one leaves, unless their own countdown has run out first.
<Toaster position="top-right" max={3} duration={4000} />- in the store0
- on screen0
Toasts appear in the top-right corner of the window. Hover or focus them to pause every countdown, including the ones waiting behind the three on screen.
From a cold start, toasts go in 3.3× faster than react-hot-toast.
Store operations run without a DOM, so they compare the libraries' own work. sonner only removes a dismissed toast after its mounted Toaster animates, so it sits out the headless rows; its Toaster does not render under happy-dom, so it sits out the commit row. It is measured on cold creation. The commit row is happy-dom, a JavaScript DOM: read it as relative.
- cold create vs react-hot-toastwin3.3×
- cold create vs sonnerwin2.5×
- headless store ops vs react-hot-toastwin2.5–3.8×
- DOM commit vs react-hot-toast (happy-dom)win21–31×, happy-dom only
Everything a toast needs, nothing to wire.
toast(message, options)Returns an id you can update or dismiss later.- Presets
toast.success,.error,.warning,.info, and.loading, which stays until you update it. toast.promiseLoading, then success or error with the result or the error in the message; returns your promise.toast.update(id, …)Change message, type or duration in place, without a new toast.- Actions
{ label: 'Undo', onClick: ({ dismiss }) => … }with the toast's own dismiss. - Rich content JSX in
message,descriptionandicon. - Soft and hard removal
dismissanimates out (200 ms) and firesonDismissonce;removeis instant. - Three pause holds Hover, keyboard focus and a hidden tab, with the remaining time kept.
<Toaster>propsposition(top or bottom; left, center or right),max,gap,offset,duration.- Reduced motion Transitions switch off under
prefers-reduced-motion: reduce.
Things to build with it.
An interceptor in your HTTP layer, no component involved.
import { toast } from '@pyreon/toast'
export async function api<T>(path: string): Promise<T> {
const res = await fetch(path)
if (!res.ok) {
toast.error(`Request failed (${res.status})`, {
description: path,
// a retry that fails toasts again; it does not hand data back to the first caller
action: { label: 'Retry', onClick: ({ dismiss }) => { dismiss(); api(path).catch(() => {}) } },
})
throw new Error(`[app] ${path} → ${res.status}`)
}
return res.json() as Promise<T>
}Delete at once, offer Undo for five seconds, and commit only if nobody clicked it.
function removeTask(task: Task) {
tasks.update((ts) => ts.filter((t) => t.id !== task.id))
let undone = false
toast('Task deleted', {
duration: 5000,
action: {
label: 'Undo',
onClick: ({ dismiss }) => {
undone = true
tasks.update((ts) => [...ts, task])
dismiss()
},
},
onDismiss: () => { if (!undone) void deleteOnServer(task.id) },
})
}One function, one component.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- toast
- toast.success
- toast.error
- toast.warning
- toast.info
- toast.loading
- toast.promise
- toast.update
- toast.dismiss
- toast.remove
- Toaster
- Toast
- ToastOptions
- ToastAction
- ToastActionContext
- ToasterProps
- ToastPosition
- ToastPromiseOptions
- ToastState
- ToastType
Good to know before you start.
Beyond max, older toasts wait unseen
The newest max toasts (5 by default) are on screen. Older ones keep their own countdown and come back when a newer one leaves, if they have not timed out. Raise max or use a dialog for messages that must be read.
One position per Toaster
position is a Toaster prop, so every toast shares it. There is no per-toast position, collapsed stack or swipe-to-dismiss.
Mount the Toaster on the client
toast() on the server is a no-op with a dev warning: a request has no screen to show it on.
Native gets the core
iOS and Android lower toast() and <Toaster> with literal options. The native overlay, with description, action and onDismiss, lands in the next release. toast.promise, toast.update, a JSX description and icons stay web and warn by name; the hover pause is web-only. Native targets are experimental.
What people ask first.
Do I need a provider?
No. The store is a module-level signal. <Toaster /> renders it through a portal, and toast() works from any module once the Toaster is mounted.
Where do the speed numbers come from?
The toast row of the record: store operations against react-hot-toast 2.5–3.8×, cold creation 3.3× vs react-hot-toast and 2.5× vs sonner, one run under bun. The record also lists a 21–31× DOM-commit figure, measured under happy-dom, so we do not lead with it.
Is it accessible?
Each toast has the live-region role for its urgency and aria-atomic; the stack is a labelled region; keyboard focus pauses the countdown; dismiss and action buttons are real buttons.
Can a toast stay until the work finishes?
Yes: toast.loading('Saving…') has no timeout. toast.update(id, { type: 'success', message: 'Saved', duration: 4000 }) turns it into a normal toast, or let toast.promise do both.
Saved. (That was a toast.)
bun add @pyreon/toast