1、ES6语法的引入,砍掉了getDefaultProps和getInitialState

getDefaultProps 使用 static default={}的方式代替
getInitialState 使用 state属性替代,初始化可以写在constructor里,也可以写成类属性

2、下一代React版本,生命周期又有改变 

componentWillMount – 使用constructor或componentDidMount代替
componentWillUpdate – 使用componentDidUpdate代替
componentWillReceiveProps – 使用一个新的方法:static getDerivedStateFromProps来代替

React 16.3版本中:

componentWillMount,componentWillUpdate,componentWillReceiveProps还能用

React 16.x版本中:

启用弃用警告,三个方法变为:

UNSAFE_componentWillMount
UNSAFE_componentWillReceiveProps
UNSAFE_componentWillUpdate

在React17.0版本中:

会移除这三个周期。

详见https://github.com/facebook/react/issues/12152

3. static getDerivedStateFromProps

在下列三种情况下,会调用getDerivedStateFromProps方法:

1. 组件实例化。
2. 组件的props发生变化。
3. 父组件重新渲染。

this.setState()不会触发getDerivedStateFromProps(),但是this.forceUpdate()会。
在update阶段也会调用一次这个方法。

最新文章

  1. Linux系统编程:基本I/O系统调用
  2. 记录vmware虚拟机安装的时候一些注意
  3. HDU 1698 Just a Hook(线段树/区间更新)
  4. 在没装VS2010的机器上运行VS2010开发的C++程序
  5. springMVC搭建
  6. 第三十三章 metrics(1) - graphite搭建 + whisper存储模式 + 高精度向低精度聚合方式 + 集成StatsD + 集成grafana
  7. RecyclerView (一) 基础知识
  8. Android中xml设置Animation动画效果详解
  9. JS和C# 互相调用与数据绑定问题
  10. 慕课网-安卓工程师初养成-2-10 Java中的强制类型转换
  11. 基于nodejs的消息中心
  12. java中的Package语句和import语句
  13. Linux智能小开关rfkill
  14. 权限的分类(shiro项目中来的五)
  15. 对国内IoT的展望
  16. Spring Boot 的 application.properties
  17. 国庆JAVA作业
  18. 【LeetCode每天一题】Pow(x, n)(平方)
  19. 配置Hanlp自然语言处理进阶
  20. (转)android系统架构及源码目录结构

热门文章

  1. PS 拉伸大长腿
  2. 第六模块:WEB框架开发 第1章·Django框架开发1~50
  3. lintcode172 删除元素
  4. 大理石在哪儿 (Where is the Marble?,UVa 10474)
  5. Centos7下部署activeMQ消息队列服务
  6. Apache--Override参数详解
  7. 改maven下创建的动态网站依赖的jre版本
  8. Simple Pipelined Function
  9. HADOOP docker(九):hdfs权限
  10. 关于LNMP常见问题和性能方面的个人理解