React问题汇总
2016-06-20 10:29
441 查看
1. 调用已经写在的组件的setState 方法,导致错误
问题: warning.js:45 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the TreeSelect component.
解决方案:
在 组件卸载的生命周期里面, 把在组件外部定义的变量 设置为 null, 这样JS的垃圾回收机制就会把 组件外部定义的变量 回收. 而不造成 内存泄露
注意: 如果在 getinitialState 里面注册的事件, 需要在 componentWillUnmount 里面清除掉, 否则容易造成内存泄露
问题: warning.js:45 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the TreeSelect component.
解决方案:
在 组件卸载的生命周期里面, 把在组件外部定义的变量 设置为 null, 这样JS的垃圾回收机制就会把 组件外部定义的变量 回收. 而不造成 内存泄露
componentWillUnmount(){ treeNodeClickHandler = null },
注意: 如果在 getinitialState 里面注册的事件, 需要在 componentWillUnmount 里面清除掉, 否则容易造成内存泄露
相关文章推荐
- windows下安装android版reactnative
- React Native学习笔记(四)Flex布局
- React Native入门学习笔记一(环境搭建windows+android)
- 学习react-native之加入redux
- 学习react-native之Navigator
- React Native es6 单例例子
- React Native es6继承(Component例子)
- React Native基本语法
- ReactiveCocoa - 基础篇
- Reactor模式
- 【转】Reactor与Proactor两种模式区别
- 在 React 中使用 semantic-ui
- react从入门到放弃 之 redux
- Redux 学习笔记(一)
- React Native 从入门到原理
- 通往全栈工程师的捷径 —— React
- React/React Native 的ES5 ES6写法对照表
- Windows下搭建React Native Android开发环境
- 抛砖引玉:如何在 React 中使用 semantic-ui 的 fixed menu 和 sidebar
- React: ES5 和 ES6 比较