React Toast Notifications
A React toast is a glass notification that stacks, fans out on hover and can be swiped away, announced automatically to screen readers.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.jsonRelease 4.2
- Build4.2s
- Deploy3 regions
- Health checkeu-west
ToasterToastProvideruseToastdefaultToasterLabels- +2 more
Files to copy
6 folders · 5 files · 4 packages
- From
theme/src/ components/toast/components/spinner/hooks/{use-direction.ts, use-media-query.ts}motion/tokens.tslib/{cn.ts, state-light.tsx}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.jsonRegistry item: toast. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Position
Pick an edge and a side, then stack a few. The newest toast sits at the edge and older ones peek out behind it; hover the stack (or press F6) to fan it out. Swipe a toast up or right to dismiss it.
import { ToastProvider, useToast } from "@/components/sheenui/toast/toast";
import { Toaster } from "@/components/sheenui/toast/toaster";
// Package build (after the first npm release, or a packed tarball): import { ToastProvider, Toaster, useToast } from "@sheenui/theme";
function App() {
const toast = useToast();
return <button onClick={() => toast.info("Hello from the toast stack")}>Show a toast</button>;
}
// Once, at the app root (top-right is the default):
export function Root() {
return (
<ToastProvider>
<App />
<Toaster />
</ToastProvider>
);
}Types
Success, error and info each get their own icon color. Fire a few in a row to see them stack.
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { useToast } from "@sheenui/theme";
const toast = useToast();
toast.success("Changes saved", "Your profile is up to date.");
toast.error("Upload failed", "The file is larger than 10 MB.");
toast.info("New version available");
toast.dismiss(); // close them allPromise, action, persistent and update
toast.promise shows one toast that turns into success or error. An action adds a button such as Undo. persistent keeps a toast until it is dismissed, and update edits one by id.
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { useToast } from "@sheenui/theme";
export function Example() {
const toast = useToast();
const save = () =>
toast.promise(new Promise<string>((resolve) => setTimeout(() => resolve("report.pdf"), 1500)), {
loading: "Saving report…",
success: (name) => `${name} saved`,
error: "Could not save",
});
const remove = () =>
toast.warning("Message deleted", undefined, { action: { label: "Undo", onClick: () => toast.success("Restored") } });
const upload = () => {
const id = toast.loading("Uploading…", "0 of 3 files");
setTimeout(() => toast.update(id, { type: "success", title: "Upload complete", description: "3 of 3 files", duration: 4000 }), 1800);
};
return (
<>
<button onClick={save}>Promise</button>
<button onClick={remove}>Action</button>
<button onClick={upload}>Update by id</button>
<button onClick={() => toast.info("Stays until closed", undefined, { persistent: true })}>Persistent</button>
</>
);
}Props
ToasterLabels keys and English defaults (4)
Keyboard
Accessibility
- Toasts are announced through a polite live region (errors too) and never steal focus. A toast with an action adds a hidden line to that announcement: "Press F6, then Tab to reach Undo."
- A toast with an action stays until it is dismissed (WCAG 2.2.1); an explicit duration on it is raised to at least 20 s. Timers also pause while a toast is hovered or focused. Still offer the same action somewhere in the page (an Undo in the list, say).
- The stack expands, and each toast pauses its timer, while it is hovered or holds focus, so there is time to read.
- Every action in a toast needs a visible label; swipe towards the nearest edge dismisses it on touch.
All exports on this page
ToastProvider— Glass toasts that stack, expand on hover and can be swiped away.Toaster— The fixed viewport that renders the toast stack.defaultToasterLabels— English defaults of ToasterLabels.useToast— const toast = useToast() returns the functions that show toasts.
When to use Toast
- Use Toast as an animated toast in React for short, non-blocking feedback such as Saved, Copied to clipboard or Invite sent, where the person can keep working and the message needs no answer. If you are comparing a sonner alternative, SheenUI's Toast is called through the useToast hook and styled with the same glass tokens as the rest of the kit.
- Use toast.error for a failed background request, such as a sync that did not finish, with a description line explaining what to try next.
- Use position on Toaster for bottom-center on a mobile-first app or top-right on a desktop dashboard, remembering that on phones every position spans the screen width.
- Skip it when the message must stay visible next to a form or needs a decision. Use Alert for persistent inline messages and Dialog or AlertDialog when the person must answer.
- Pair it with Button actions that call useToast, Switch and Checkbox settings that save instantly, and DataTable bulk actions that finish in the background.
Choosing between SheenUI Toast and Sonner
Sonner is a popular React toast library built around one global toast() call. SheenUI's toast is built on Base UI's Toast: you wrap the app in ToastProvider, render one Toaster and call useToast() for toast.success, toast.info, toast.error and toast.dismiss. Toasts stack, expand on hover or focus, can be swiped away, pause their timer while hovered or focused and fade under reduced motion. Choose Sonner if you want a global function and nothing to provide; choose this one if you want glass styling, Base UI's accessibility model and the source in your own repository.
Frequently asked questions
Related pages
Guides that cover it
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .