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

 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.

 

 

解决:

componentWillUnmount里面增加 this.setState = () => false;   意思是将this.setState设置为false

例如:
  componentWillUnmount() {
     this.setState = () => false;
  }

  出现原因:某些时候请求接口数据加载比较慢,这时候setState还未完成,用户切换了组件或者切换页面时候,组件卸载了,而这个setState动作还在持续,所以react会出现警告

 

posted @ 2020-08-18 11:17  月亮出来了  阅读(4345)  评论(0编辑  收藏  举报