美文网首页
高效学习 react 笔记六:生命周期

高效学习 react 笔记六:生命周期

作者: littleyu | 来源:发表于2019-07-01 22:21 被阅读0次

先来看React v16.3之前的生命周期函数(图中实际上少了componentDidCatch),如下图。

constructor
componentWillMount
render
componentDidMount
componentShouldUpdate
componentWillUpdate
render
componentDidUpdate
componentWillUnmount
componentWillReceiveProps

所以,React v16.3之后的生命周期函数一览图成了这样。

总结一下:

用一个静态函数getDerivedStateFromProps来取代被deprecate的几个生命周期函数,就是强制开发者在render之前只做无副作用的操作,而且能做的操作局限在根据props和state决定新的state,而已。

相关文章

网友评论

      本文标题:高效学习 react 笔记六:生命周期

      本文链接:https://www.haomeiwen.com/subject/eznrqctx.html