React生命周期的执行顺序如下: 初始化阶段(Mounting):组件被创建并插入到DOM中 constructor() staticgetDerivedStateFromProps() render() componentDidMount() 更新阶段(Updating):组件的props或state发生变化,导致重新渲染
React生命周期的执行顺序如下:
-
初始化阶段(Mounting):组件被创建并插入到DOM中
- constructor()
- staticgetDerivedStateFromProps()
- render()
- componentDidMount()
-
更新阶段(Updating):组件的props或state发生变化,导致重新渲染
- staticgetDerivedStateFromProps()
- shouldComponentUpdate()
- render()
- getSnapshotBeforeUpdate()
- componentDidUpdate()
-
卸载阶段(Unmounting):组件被从DOM中移除
- componentWillUnmount()
-
错误处理阶段(ErrorHandling):组件渲染过程中出现错误
- staticgetDerivedStateFromError()
- componentDidCatch()
版权声明
本文仅代表作者观点,不代表博信信息网立场。