React V7版本一些新的生命周期函数

Dear 丶 2023-06-06 12:25 67阅读 0赞

Mount阶段:

  • constructor()
  • static getDerivedStateFromPro ps():返回一个对象来更新 state,如果返回 null 则不更新任何内容。(componentWillMount() / UNSAFE_componentWillMount()//被废弃)
  • render()
  • componentDidMount()

Update阶段:

(componentWillReceiveProps() / UNSAFE_componentWillReceiveProps()//被废弃)

  • static getDerivedStateFromProps()
  • shouldComponentUpdate()

componentWillUpdate() / UNSAFE_componentWillUpdate()//被废弃

  • render()
  • getSnapshotBeforeUpdate():返回值将传给componentDidUpdate()的第三个参数 ,否则第三个参数将为undefined。
  • componentDidUpdate()

Unmount阶段:

  • componentWillUnmount()

图例更清晰:
图例更清晰

捕获错误的生命周期函数

  • static getDerivedStateFromError():在后代组件抛出错误后被调用。
  • componentDidCatch():在后代组件抛出错误后被调用。

发表评论

表情:
评论列表 (有 0 条评论,67人围观)

还没有评论,来说两句吧...

相关阅读