@allenfang/react-toastr

中文文档
2.8.2发布于 2016/12/13MITCommonJS近 30 天下载 3341

React.js toastr component

原始使用文档
文档目录6 节
  1. Installation
  2. Demo
  3. Example
  4. Usage
  5. ToastContainer
  6. ToastMessage

react-toastr

React.js toastr component

Version Travis CI Quality Coverage Dependencies Gitter

Installation

npm i --save react-toastr

Demo

Static hosted demo site on GitHub.

Example

Check src/app folder.

Usage

This module requires to be bundled with webpack/browserify and loads react/addons internally.
You'll need to download animate.css from here Animate @github

Link to css for styles:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.3/toastr.min.css">

Then:

var ReactToastr = require("react-toastr");
var {ToastContainer} = ReactToastr; // This is a React Element.
// For Non ES6...
// var ToastContainer = ReactToastr.ToastContainer;
var ToastMessageFactory = React.createFactory(ReactToastr.ToastMessage.animation);

  // In a react component:
  render () {
    return (
      <div>
        <ToastContainer ref="container"
                        toastMessageFactory={ToastMessageFactory}
                        className="toast-top-right" />
        <button onClick={this.addAlert}>GGininder</button>
      </div>
    );
  }

Here's a list of React Elements:

ToastContainer

This is the container where all ToastMessage elements will go. Use it by retaining a ref to publish a new toast message:

  addAlert () {
    this.refs.container.success(
      "Welcome welcome welcome!!",
      "You are now home my friend. Welcome home my friend.", {
      timeOut: 30000,
      extendedTimeOut: 10000
    });
    window.open("http://youtu.be/3SR75k7Oggg");
  }

or integrated with your flux architecture?

  componentDidMount: function() {
    InInDerStore.addChangeListener(this.addAlert);
  }

Options

Directly migrated from toastr.js library, and can be overrided via props in a React way:

ToastContainer::getDefaultProps

Close Button

The close button on the toastr is an optional functionality.

  closeButton:true
Time Out

Set the time(in ms) after which the toastr message should automatically close.

  timeOut:5000
Prevent Duplicates

This prevents duplicate messages from getting triggered.

  preventDuplicates:true

Displaying HTML

To display HTML simply pass JSX instead of strings for title and message arguments:

this.refs.container.success(
  <strong>I am a strong title</strong>,
  <em>I am an emphasized message</em>
});

ToastMessage

Base class for holding a toast message, it will not animate in and out during it's lifecycle. Provides ToastMessage.animation and ToastMessage.jQuery for your choice.

Options

Directly migrated from toastr.js library, and can be overrided via props in a React way:

版本与发布记录

@allenfang/react-toastr 共发布 1 个版本,首次发布于 2016/12/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.8.2latest2016/12/139 年前

关于 @allenfang/react-toastr 的常见问题

@allenfang/react-toastr 是什么?

React.js toastr component

如何安装 @allenfang/react-toastr?

在项目目录运行 npm install @allenfang/react-toastr,或使用 pnpm add / yarn add / bun add。

@allenfang/react-toastr 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/allenfang__react-toastr 是否存在。

@allenfang/react-toastr 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@allenfang/react-toastr 可以商用吗?

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

@allenfang/react-toastr 的下载量有多少?

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

@allenfang/react-toastr 还在维护吗?

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