类组件的生命周期 挂载时

父子的类组件生命周期如下
box.constructor-->box.getDerivedStateFromProps-->box.render--> son.constructor-->son.getDerivedStateFromProps-->son.render-->son.componentDidMount-->box.componentDidMount
父组件执行到render,然后执行子组件
react 类组件的生命周期

类组件的生命周期 更新时

box.getDerivedStateFromProps-->box.shouldComponentUpdate-->box.render-->son.getDerivedStateFromProps-->son.shouldComponentUpdate-->son.render-->son.getSnapshotBeforeUpdate-->box.getSnapshotBeforeUpdate-->son.componentDidUpdate-->box.componentDidUpdate
react 类组件的生命周期

类组件的生命周期 卸载时

box.componentWillUnmount -->son.componentWillUnmount
react 类组件的生命周期

代码地址:https://codesandbox.io/s/react-lifecycle-2fif0

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2021-12-22
  • 2021-08-12
  • 2021-07-05
相关资源
相似解决方案