组件的生命周期分为三个状态

Mounting: 已插入真实DOM
Updateing: 正在被重新渲染
Unmounting: 已移出真实DOM

React 为每个状态都提供了两种处理函数,即函数在进入状态之前调用(will函数),函数在进入状态之后调用(did函数),三种状态共计五中处理函数。

componentWillMount()
componentDidMount()
componentWillUpdate(object nextProps, object nextState)
componentDidUpdate(object prevProps, object prevState)
componentWillUnmount()

此外,React还提供了两种特殊状态的处理函数

componentWillReceiveProps(object nextProps): 已加载组件收到新的参数时调用
shouldComponentUpdate(object nextProps, object nextState): 组件判断是否重新渲染时调用

相关文章:

  • 2021-12-03
  • 2019-05-22
  • 2021-07-31
  • 2021-07-05
  • 2021-07-03
猜你喜欢
  • 2021-11-28
  • 2022-01-11
  • 2021-12-06
  • 2021-10-30
  • 2022-12-23
  • 2022-01-14
相关资源
相似解决方案