首页 > 其他 > 详细

React V16.x 生命周期调整

时间:2018-09-23 15:28:28      阅读:136      评论:0      收藏:0      [点我收藏+]

生命周期 | 属于阶段 | 是否可以setState | 作用
constructor() | 创建阶段 Mounting | | 注意:ES6 子类的构造函数必须执行一次 super()。React 如果构造函数中要使用 this.props,必须先执行 super(props)。
getDerivedStateFromProps | 当创建时、接收新的 props 时、setState 时、forceUpdate 时会执行 || 注意:v16.3 setState 时、forceUpdate 时不会执行这个方法,v16.4 修复了这个问题。

  • 逐渐废弃的生命周期方法(3个Will):
componentWillMount()
componentWillReceiveProps()
componentWillUpdate()

虽然废弃了这三个生命周期方法,但是为了向下兼容,将会做渐进式调整。
V16.3 并未删除这三个生命周期,同时还为它们新增以 UNSAFE_ 前缀为别名的三个函数 UNSAFE_componentWillMount()、UNSAFE_componentWillReceiveProps()、UNSAFE_componentWillUpdate()。
在 16.4 版本给出警告将会弃用 componentWillMount()、componentWillReceiveProps()、componentWillUpdate() 三个函数
然后在 17 版本将会删除 componentWillMount()、componentWillReceiveProps()、componentWillUpdate() 这三个函数,会保留使用 UNSAFE_componentWillMount()、UNSAFE_componentWillReceiveProps()、UNSAFE_componentWillUpdate()

  • 一般将生命周期分成三个阶段:
    创建阶段(Mounting)
    更新阶段(Updating)
    卸载阶段(Unmounting)

React V16.x 生命周期调整

原文:https://www.cnblogs.com/cag2050/p/9692757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!