首页 > 移动平台 > 详细

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

时间:2020-08-18 11:50:49      阅读:74      评论:0      收藏:0      [点我收藏+]

 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会出现警告

 

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

原文:https://www.cnblogs.com/seemoon/p/13522432.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!