@aminekun90/react-toast

中文文档
1.3.0发布于 2026/10/21MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 7.6万

A lightweight, high-performance, and Hook-based toast notification library for React 18 & 19.

原始使用文档
文档目录16 节
  1. Demo app
  2. Key Features
  3. Installation
  4. Peer Dependencies
  5. Configuration
  6. Usage
  7. 1. Add the Global Container
  8. 2. Triggering Notifications
  9. 3. Global defaults (optional)
  10. 4. Loading & Promise toasts
  11. API Reference
  12. ToastConfig Properties
  13. Theming
  14. Compatibility
  15. Keep this project alive :coffee:
  16. License

@aminekun90/react-toast 🍞

A lightweight, high-performance, and Hook-based toast notification library for React 18 & 19.

React Version Maintenance version number License node-current NPM

Demo app

View React Demo

Shares its core engine and stylesheet with the Angular library @aminekun90/ngx-toast — identical behavior and themes.

Key Features

  • ⚛️ React 18 & 19 Ready: Full support for Concurrent Mode and the latest React features.
  • ⚓ Hook-based API: Simple and intuitive useToast() hook to trigger notifications.
  • 🎨 FontAwesome Integration: Professional iconography baked-in.
  • ♿ Accessible: role="alert", aria-live, keyboard dismissal (Enter/Space/Escape), focus styles.
  • ⏸️ Pause on hover: Timer and progress bar pause while hovered/focused.
  • 🌙 Themes & dark mode: 5 built-in themes, full CSS-variable customization, automatic dark mode.
  • 🧩 Global defaults: Configure position, duration, max stack, dedup via <ToastProvider config>.
  • 🔁 Promise & loading toasts: loading() and promise() helpers that swap in place.
  • 📦 Tiny: Small bundle, optimized with Vite, zero extra runtime deps.

Installation

Install the package via Yarn:

yarn add @aminekun90/react-toast

Peer Dependencies

Ensure you have the following dependencies installed (required for icons and peer-matching):

yarn add @fortawesome/react-fontawesome @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons

Configuration

Wrap your application (or the desired part of your tree) with the ToastProvider.

import { ToastProvider } from '@aminekun90/react-toast';

export function App() {
  return (
    <ToastProvider> <!-- Mandatory -->
      <MyMainComponent />
    </ToastProvider>
  );
}

Usage

1. Add the Global Container

Place the ToastContainer at the root of your application (usually in App.tsx). It will manage the stacking of all active notifications.

import { ToastContainer } from '@aminekun90/react-toast';

export default function App() {
  return (
    <div className="app-root">
      <ToastContainer />
      <MyContent />
    </div>
  );
}

2. Triggering Notifications

Use the useToast hook anywhere inside your ToastProvider.

import { useToast } from '@aminekun90/react-toast';

export function MyComponent() {
  const { success, error, info, warning } = useToast();

  const handleAction = () => {
    success('Operation successful!', 'Success');
  };

  return <button onClick={handleAction}>Click me</button>;
}

3. Global defaults (optional)

<ToastProvider config={{
  position: 'top-right',
  duration: 4000,
  pauseOnHover: true,
  maxToasts: 5,
  preventDuplicates: true,
  newestOnTop: true,
}}>
  <App />
</ToastProvider>

4. Loading & Promise toasts

const { loading, success, promise } = useToast();

const id = loading('Uploading…');
// later: success('Done!', undefined, { id });

await promise(saveUser(), {
  loading: 'Saving…',
  success: (user) => `Saved ${user.name}`,
  error: (err) => `Failed: ${err}`,
});

API Reference

MethodReturnsDescription
show(config)numberDisplay a toast; returns its id. Reusing an id updates it in place.
success/error/warning/info(message, title?, config?)numberTyped shortcuts.
loading(message, title?, config?)numberPersistent loading toast.
promise(promise, msgs, config?)Promise<T>Loading → success/error, swapped in place.
remove(id)voidDismiss a single toast.
clear(position?)voidDismiss all toasts, optionally by position.
pause(id) / resume(id)voidPause/resume the auto-dismiss timer.

ToastConfig Properties

PropertyTypeDefaultDescription
type'success' | 'error' | 'warning' | 'info' | 'loading''info'Visual theme and icon.
titlestringundefinedOptional bold heading.
messagestring—Primary text content.
durationnumber5000Time in ms (0 = persistent).
positionToastPosition'bottom-right'Screen placement.
progressBarbooleanfalseDisplays a countdown bar.
progressAnimation'increasing' | 'decreasing''increasing'Bar direction.
iconIconDefinitionby typeCustom FontAwesome icon.
toastClassstring''Extra CSS class.
pauseOnHoverbooleantruePause on hover/focus.
themestringundefinedmaterial | glass | minimal | neon | solid or custom.

Theming

Five built-in themes, applied per toast or globally; everything is CSS-variable driven for full customization.

success('Saved!', undefined, { theme: 'glass' });
<body class="ngx-toast-theme-material">…</body>

📖 Full reference: docs/THEMING.md · 🏗️ docs/ARCHITECTURE.md

Compatibility

PackageReact VersionNode.js Version
1.0.x^18.0.0 | ^19.0.0^22.x | ^24.x

Keep this project alive :coffee:

I dedicate time and effort to maintaining this library. If it helped you, please consider donating!

Donate via PayPal

License

MIT License, By Amine Bouzahar.

版本与发布记录

@aminekun90/react-toast 共发布 13 个版本,首次发布于 2026/03/05;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/10/2116 天前
1.2.02026/06/214 个月前
1.1.12026/03/187 个月前
1.1.02026/03/127 个月前
1.0.112026/03/117 个月前
1.0.102026/03/117 个月前

关于 @aminekun90/react-toast 的常见问题

@aminekun90/react-toast 是什么?

A lightweight, high-performance, and Hook-based toast notification library for React 18 & 19.

如何安装 @aminekun90/react-toast?

在项目目录运行 npm install @aminekun90/react-toast,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aminekun90/react-toast 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aminekun90/react-toast 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aminekun90/react-toast 可以商用吗?

@aminekun90/react-toast 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aminekun90/react-toast 的下载量有多少?

根据 npm 官方下载统计,@aminekun90/react-toast 在 2026/10/06 – 2026/11/04 这 30 天内被下载 76,410 次,日均约 2,547 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aminekun90/react-toast 还在维护吗?

最新版本 1.3.0 发布于 2026/10/21(16 天前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/03/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。