在使用react的时候,发现一个警告

Warning: setState(...):Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`

不能在现有状态转换期间更新(例如在' render '或其他组件的构造函数中)。渲染方法应该是道具和状态的纯函数;构造函数的副作用是反模式的,但是可以移动到“componentWillMount”

先开始我是这样写的:

componentDidMount(){AccountStore.listen(this.accountChange);this.accountChange();
}

然后在运行的时候,偶尔会出现警告:

setState是异步执行的,加一个this.mounted控制执行顺序:

componentDidMount(){this.mounted = true;AccountStore.listen(this.accountChange);if(this.mounted == true){this.accountChange();}
}
componentWillUnmount(){this.mounted = false
}

警告就没有了

react警告:setState(...): Cannot update during an existing state transition (such as within `render` or相关推荐

  1. react 警告Warning: Cannot update during an existing state transition (such as within `render`). Render

    react 报错Warning: Cannot update during an existing state transition (such as within `render`). Render ...

  2. react项目报出警告Warning: Cannot update during an existing state transition (such as within `render`).

    在一次写react项目中,报出如下警告,如图: 意思大概为:在一次改变state或者props值后,触发render()方法执行,重新渲染DOM的过程中,react不允许再有其他的state或者pro ...

  3. React使用路由跳转时控制台报Cannot update during an existing state transition (such as within `render`)错误

    React使用路由跳转时控制台报Cannot update during an existing state transition (such as within render).Render met ...

  4. Warning: Cannot update during an existing state transition (such as within `render`). Render methods

    在使用react开发项目时,报了这个错误 原因:在render的时候使用setState()方法改变了state,它应该是一个纯的函数,不应该在这个方法当中去改变state

  5. Warning: Cannot update during an existing state transition (such as within `render`)

    原来的代码是: 报错信息如下: 修改为: 这样就不报错了.

  6. 报错:Cannot update during an existing state transition (such as within `render`).

    问题描述:在使用Form组件 为组件赋值时候 存在的warning 翻译: 在现有状态转换期间(例如在`render`中)无法更新.渲染方法应该纯粹是props和state的函数. 解决方式, 在us ...

  7. react 之 setState

    setState()是react为我提供的状态管理工具 比如现在有下面的这样一段代码: class MyComponent extends React.Component { constructor( ...

  8. React 项目----setState 方法修改 state (16)

    在class 类中,构造器里面有一个实例变量state ,这个也是class 组件和function组件之间的区别.class 组件有自己的私有的数据 export default class Bin ...

  9. react使用setState注意事项

    React设计setState方法就是为了重新渲染页面 看看下面的代码实现的结果: state = {value : 0 }function test() {this.setState({ value ...

最新文章

  1. UNITY 多个子MESH与贴图的对应关系
  2. mysql忘记密码,如何重置密码
  3. 解决1px的border在移动端变粗的问题
  4. openstack-mitaka之Telemetry服务(controller安装部署)
  5. 远程仓库都不知道,那你学Git干嘛?
  6. linux 基本指令-线上运维
  7. typora公式zuo对齐_Markdown编辑神器-Typora
  8. 重庆大二学生花了6年写出了操作系统
  9. 互联网公司的架构设计要怎么落地?| 技术头条
  10. rfid水洗电子标签怎么管理洗涤衣物
  11. 查看服务器的外网IP
  12. 功能对等四个原则_“奈达功能对等理论”四个方面的原始出处及定义是什么?...
  13. Learning to Reconstruct 3D Manhattan Wireframes from a Single Image 翻译
  14. 编写函数求x的n次方
  15. 【文末有惊喜!】iOS日历攻略:提醒调休并过滤法定节假日
  16. Java中哈希集(HashSet)概念,实现以及操作
  17. 霍尔传感器及其在BLDC电机上的应用
  18. 整理了一波技术博主超好用的工具!
  19. java 一元 二元 三元_一元到三元关系 二元
  20. 现代企业管理-管理概论

热门文章

  1. 幽默笑话,领奖磕头行礼,木子家原创
  2. The Sandbox 与狮门影业达成合作,在元宇宙创建电影主题的娱乐乐园
  3. android ndk standalone,Android NDK make-standalone-toolchain因mips而失败
  4. python用来做什么好_Python可以被用来做哪些神奇好玩的事情
  5. SQL报错盲注绕过云锁
  6. enctype=“multipart/form-data“表单传值问题
  7. JPA之使用复合主键
  8. Envi4.5几何纠正
  9. JSTL——jstl标签简介
  10. 如何建一个团队博客(宿舍四人为例)