您的位置:首页 > Web前端 > React

react报错: 切换路由时,上一个组件已卸载,但是它的异步更新状态还没有执行完,所以报错

2020-07-15 06:04 1256 查看

报错: Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
Goole 翻译: 无法在已卸载的组件上执行React状态更新。 这是空操作,但它表明应用程序中发生内存泄漏。 要解决此问题,请在componentWillUnmount方法中取消所有订阅和异步任务。

react项目切换路由的时候, 一直报这个错误,

最后在 点击按钮切换路由的那个页面,加了个卸载生命周期 componentWillUnmount

componentWillUnmount() {
this.setState = () => {
return;
};
};

好了…

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐