Lightweight external store managing a capped queue of dismissible UI toast notifications without auto-timeout. Reuse for React apps needing manual-dismiss notices.
// Source: https://github.com/esengine/DeepSeek-Reasonix | License: MIT | Copyright 2026 Reasonix Contributors
// Provided via justclaw.it.com; keep this notice with the code.
import { useSyncExternalStore } from "react";
// The small notices a failed action leaves in the window's corner. They do not
// time out: only the person who was told decides they were read. A fourth one
// pushes the oldest out, so the corner never grows past what fits beside the work.
export interface Toast {
id: number;
text: string;
// A note tells the person what the window did on its own; it is not a failure.
tone?: "note";
}
export const MAX_TOASTS = 3;
let toasts: readonly Toast[] = [];
let serial = 0;
const listeners = new Set<() => void>();
const publish = (next: readonly Toast[]) => {
toasts
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key