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 ...
随机推荐
- Web上传文件的原理及实现
现在有很多Web程序都有上传功能,实现上传功能的组件或框架也很多,如基于java的Commons FileUpload.还有Struts1.x和Struts2中带的上传文件功能(实际上,Struts2 ...
- 从Elasticsearch来看分布式系统架构设计
分布式系统类型多,涉及面非常广,不同类型的系统有不同的特点,批量计算和实时计算就差别非常大.这篇文章中,重点会讨论下分布式数据系统的设计,比如分布式存储系统,分布式搜索系统,分布式分析系统等. 我们先 ...
- 【死磕jeesite源码】mybatis动态调用表名和字段名
本文转载自夏雪冬日 一直在使用Mybatis这个ORM框架,都是使用mybatis里的一些常用功能.今天在项目开发中有个业务是需要限制各个用户对某些表里的字段查询以及某些字段是否显示,如某张表的某些字 ...
- Unity3D Shader 内置函数
Intrinsic Functions (DirectX HLSL) The following table lists the intrinsic functions available in HL ...
- Servlet3.0 multipart 文件上传技术
Servlet3.0 javaConfig配置 传统的servlet都是在web.xml中配置,从Servlet 3.0开始提供了ServletContainerInitializer接口,允许使用代 ...
- Flask web开发之路十三
g对象 ### 保存全局变量的g属性:g:global1. g对象是专门用来保存用户的数据的.2. g对象在一次请求中的所有的代码的地方,都是可以使用的. 项目结构: g_demo.py文件代码: f ...
- thinkPHP框架 简单的删除和修改数据的做法 和 模板继承的意思大概做法
BiaodanController.class.php控制器页面 <?php namespace Admin\Controller; use think\Controller; class Bi ...
- Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer
Springboot项目,使用postgresql数据库,mybatis做持久层框架, <select id="select" resultMap="BaseRes ...
- C# chart 编程教程
http://www.gcpowertools.com.cn/docs/ComponentOne/WinFormChart/#!Documents/_41.htm
- [No0000FD]C# 正则表达式
正则表达式 是一种匹配输入文本的模式..Net 框架提供了允许这种匹配的正则表达式引擎.模式由一个或多个字符.运算符和结构组成. 定义正则表达式 下面列出了用于定义正则表达式的各种类别的字符.运算符和 ...