我正在使用 react-toastify
我无法得到一个简单的 toast 来呈现……
import React from "react";
import { toast } from 'react-toastify';
class MyView extends React.Component<{}, {}> {
constructor() {
super();
this.state = {
};
}
componentDidMount() {
toast("Hello", { autoClose: false });
}
notify = () => toast("Hello", { autoClose: false });
render() {
return (
<div>
<button onClick={this.notify}>Notify</button>
</div>
)}
}
package.json(在“依赖”部分)
"react": "^16.2.0",
"react-toastify": "^3.2.2"
如果我调试它,我会看到我的 toast 已排队,_EventManager2 永远不会获得通常从队列中发出 toast 的 _constant.ACTION.MOUNTED 事件……
/**
* Wait until the ToastContainer is mounted to dispatch the toast
* and attach isActive method
*/
_EventManager2.default.on(_constant.ACTION.MOUNTED, function (containerInstance) {
container = containerInstance;
toaster.isActive = function (id) {
return container.isToastActive(id);
};
queue.forEach(function (item) {
_EventManager2.default.emit(item.action, item.content, item.options);
});
queue = [];
});
..所以那个 ToastContainer 可能有问题但是什么?我只是使用文档中的示例代码。
谢谢您的帮助!
原文由 kevinob 发布,翻译遵循 CC BY-SA 4.0 许可协议
您还必须
import 'react-toastify/dist/ReactToastify.css';