【问题标题】:How to install react-toastr如何安装 react-toastr
【发布时间】:2018-07-17 00:41:23
【问题描述】:

我安装了 react-toastr 并集成了示例代码。

import React from 'react'
import { ToastContainer } from 'react-toastr';
class Notifier extends React.Component
{
  updateNotify()
  {
    this.refs.container.info('hola el mundo');
  }
  render()
  {
    return(
      <ToastContainer ref="container"
      className="toast-top-right" />
    );
  }
}

当我在容器上调用 info() 时,消息会弹出,但就像页面顶部的纯文本一样,而不是右上角的样式框。消息也永远不会消失。所以看起来缺少 CSS 和 JavaScript 组件。

我做错了什么?为什么在 Linux 下安装 fsevents 时会出现这些警告?如果重要的话,我正在使用 react 15。我降级到 react-toastr 2.9.5 版,但没有什么不同。

$ npm install --save react-toastr
myApp@0.3.1 /home/myApp
└─┬ react-toastr@3.0.0
  └─┬ babel-runtime@6.26.0
    ├── core-js@2.5.3
    └── regenerator-runtime@0.11.1

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.0.17 (node_modules/react-scripts/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.17: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

【问题讨论】:

    标签: reactjs toastr


    【解决方案1】:

    你需要添加toastrCSS file

    Running example

    【讨论】:

    • 确实,你是对的。另一个缺失的是 animate.css 文件。令人难以置信的是,react-toastr 文档中忽略了如此重要但微不足道的东西。下一步是了解如何从弹跳动画更改为更合理的动画,但这也神秘地没有记录:github.com/tomchentw/react-toastr/issues/133
    • 我遵循的一般规则是:每个构建在另一个库之上的react-* 库(请参阅react-bootstrapsemantic-ui-react 等...)都需要css 文件由您提供。大多数 react 库只负责 Javascript 部分。
    • 没有样式怎么办?我做npm i react-toastr,我还需要用什么? (其实没什么……)
    • node_modules/react-toastr/src/docs/configuration.md 你会找到你需要的css的引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 2020-11-21
    • 2018-09-08
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多