Linux 拨号vps windows公众号手机端

react生命周期的执行顺序是什么

lewis 8年前 (2017-01-03) 阅读数 7 #程序编程
文章标签 React

React生命周期的执行顺序如下:

  1. 初始化阶段(Mounting):组件被创建并插入到DOM中

    • constructor()
    • static getDerivedStateFromProps()
    • render()
    • componentDidMount()
  2. 更新阶段(Updating):组件的props或state发生变化,导致重新渲染

    • static getDerivedStateFromProps()
    • shouldComponentUpdate()
    • render()
    • getSnapshotBeforeUpdate()
    • componentDidUpdate()
  3. 卸载阶段(Unmounting):组件被从DOM中移除

    • componentWillUnmount()
  4. 错误处理阶段(Error Handling):组件渲染过程中出现错误

    • static getDerivedStateFromError()
    • componentDidCatch()
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门