React生命周期了解

组件的生命周期

  • 所谓的生命周期就是指某个事物从开始到结束的各个阶段,当然在 React.js 中指的是组件从创建到销毁的过程,React.js 在这个过程中的不同阶段调用的函数,通过这些函数,我们可以更加精确的对组件进行控制,前面我们一直在使用的 render 函数其实就是组件生命周期渲染阶段执行的函数
生命周期演变 以前-----现在

以前

挂载阶段

  • constructor
  • componentWillMount
  • render
  • componentDidMount
    更新阶段
父组件更新引起组件更新
  • componentWillReceiveProps(nextProps) *
  • shouldComponentUpdate(nextProps, nextState)
  • componentWillUpdate(nextProps, nextState) render
  • componentDidUpdate(prevProps, prevState)
组件自身更新
  • shouldComponentUpdate
  • componentWillUpdate
  • render
  • componentDidUpdate
卸载阶段

componentWillUnmount

现在

挂载阶段

  • constructor
  • static
  • getDerivedStateFromProps(props, state)
    注意 this 问题render componentDidMount

更新阶段

父组件更新引起组件更新
  • static
  • getDerivedStateFromProps(props, state) shouldComponentUpdate()
  • componentWillUpdate()
  • render()
  • getSnapshotBeforeUpdate()
  • componentDidUpdate()
组件自身更新
  • shouldComponentUpdate()
  • componentWillUpdate()
  • render()
  • getSnapshotBeforeUpdate()
  • componentDidUpdate()

卸载阶段

componentWillUnmount

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值