React篇-报错信息:warning: Can't call setState (or forceUpdate) on an unmounted component.
报错信息是:
Warning: Can't call setState (or forceUpdate) 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.

项目中tab切换,内容封装成来一个子组件,在跳转到别的路由页面,然后再返回该页面点击tab切换的时候报上述错误,找了很久的原因,目前得到的分析应该是,在路由跳转过来的时候子组件还未加载到,此时点击切换tab栏(这里需要setState),就会报上述的错误,解决办法如下:
设置变量 let isMounted = false
然后在componentDidMount周期设置:
componentDidMount(){
isMounted = true;
}
在componentWillUnmount周期设置:
componentWillUnmount(){
isMounted = false
}
组件render这里判断isMounted的值:
{
isMounted && this.state.activeIndex === 1 && <div className="tabC01">
<FTab tabCon={'tabCon01'}/>
</div>
}
React篇-报错信息:warning: Can't call setState (or forceUpdate) on an unmounted component.的更多相关文章
- JAVA_用_JCO连接_SAP,实现调用SAP_的_RFC_函数(整理)(附一篇看起来比较全面的说明)(JCO报错信息)
// 获取RFC返回的字段值 11 JCoParameterList exportParam = function.getExportParameterList(); 12 String exPara ...
- PHP安全编程:不要让不相关的人看到报错信息
没有不会犯错的开发者,PHP的错误报告功 能可以协助你确认和定位这些错误,可以提供的这些错误的详细描述,但如果被恶意攻击者看到,这就不妙了.不能让大众看到报错信息,这一点很重要.做到这一 点很容易,只 ...
- PHP安全编程:不要让不相关的人看到报错信息(转)
没有不会犯错的开发者,PHP的错误报告功能可以协助你确认和定位这些错误,可以提供的这些错误的详细描述,但如果被恶意攻击者看到,这就不妙了.不能让大众看到报错信息,这一点很重要.做到这一点很容易,只要关 ...
- 使用Visual Studio Code调试React Native报错
报错信息: [Error] Error: Unknown error: not all success patterns were matched. It means that "react ...
- Oauth2.0 整合springCloud的Zuul 解决关键BUG 报错信息:Principal must not be null
不清楚Oauth2.0 的 可以查看我前几篇博文 2018.4.8 补充 我出现这个原因:是我在资源服务器使用了 如下图所示 Principal Oauth2.0 提供的获取用户信息的方法 使其找到相 ...
- 【开发笔记】- Idea启动Gradle报错:Warning:Unable to make the module: reading, related gradle configuration was not found. Please, re-import the Gradle project and try again
报错信息: Warning:Unable to make the module: reading, related gradle configuration was not found. Please ...
- Maven打包报错:[WARNING] The POM for xxx is missing, no dependency inform
maven install 或 package 时 ,执行警告报错: [WARNING] The POM for com.xx-base:jar:1.0 is missing, no dependen ...
- Docker报错:“WARNING: IPv4 forwarding is disabled. Networking will not work.”解决。
问题阐述 一次停电之后,服务器停机,然后ip莫名被占用,修改新的ip之后,ssh能够连接上去,但是web服务访问不了,数据库访问不了,除了22端口,其它服务端口都不能telnet. 防火前.IPtab ...
- phpredis报错信息:protocol error, got 'o' as reply type byte解决方案
今天在前端调用PHP的接口时,有报错信息为:protocol error, got 'o' as reply type byte另外此错误有几率会重现,并不是必现的.十分疑惑,遂百度一下,发现是red ...
随机推荐
- 使用kill -9 进程ID杀死jps中进程
- web.xml配置DispatcherServlet (***-servlert.xml)
1. org.springframework.web.servlet.DispatcherServlet 所在jar包: <dependency> <groupId>org.s ...
- mkvirtualenv command not found解决
在京东云上用户家目录下创建.virtualenvs后,创建python虚拟环境,使用mkvirtualenv命令,没有提示,输完回车报下面错误,mkvirtualenv command not fou ...
- 1. Mysql数据库的安装
1. Mysql数据库的安装 (1)打开Mysql安装软件,同意相关协议进入下一步安装,在选择安装类型中选择[自定义]进入下一步安装. (2)选择安装的组件信息. (3)服务器软件安装目录 (4)数据 ...
- 更新docker时间-需要重启docker
更新docker时间:1.docker run -d -v /etc/localtime:/etc/localtime:ro [IMAGE] 2.重启,docker-compose up -d 3.d ...
- python 中 try ...except
捕捉异常 try: 下的代码段 即为 需要捕捉异常的代码段: except: 捕获某一模块的异常,须带异常模块名称,可带原因参数:except 下代码为该异常发生时,所执行的代码:一个try可对应多 ...
- 正则表达式、re模块
正则表达式 一说规则我已经知道你很晕了,现在就让我们先来看一些实际的应用.在线测试工具 http://tool.chinaz.com/regex/ 正则表达式是用来匹配字符串非常强大的工具,在其他编程 ...
- python-Beautiful rose
热爱python,热爱生活,python需要浪漫,让我带大家走进浪漫的国度...写的不好的地方请大佬指教 import turtle import time class Rose: def __ini ...
- 常用Common集合
Log using System; using System.IO; using System.Linq; using System.Text; namespace Common { public c ...
- C# 单元测试能过,但Web项目就报错!
第一印象肯定是两个项目中各有不同的地方 背景: 公司项目采用IBatic+Castle实现 排查过程: 1.sqlmap文件是否一至,并且读取位置也要正确 2.dao.config文件要一至,读取位置 ...