我最近开始使用react-toastify,一切都运行得很好,直到我注意到这个奇怪的行为。
下面是我的代码:this.adderrorNotification('Error: Please try again!')
adderrorNotification(message){
toast.error(message, {
onClose: () => console.log('called when I close')
});
}

在toast onClose上,我看到了4次日志消息。然后在手动关闭时,单击toast再次出现4次。
为什么会发生这种情况?有什么帮助吗?谢谢
发布于 2021-05-29 12:36:58
回答我自己的问题:
原因:在导致问题的所有组件中初始化了toast。(侧边栏,导航栏,主要组件,页脚),这是渲染4次。
解决方案:删除所有组件中的toast初始化并在index.js中对其进行初始化,解决了我的问题。
https://stackoverflow.com/questions/67732468
复制相似问题