5.react之生命周期(旧)

旧声明周期
如图所示,react的生命周期分为挂载时和更新时
挂载时:constructor->componentWillMount->render->componentDidMount
卸载时:componentWillUnmount(通过reactDom.onmountComponentAtNote()卸载)
更新时:分三种情况
(1)父组件render后子组件也render,
(2)通过setState()修改状态,
(3)通过forceUpdate()强制更新
(1)父组件render子组件也render
生命周期执行顺序如下:
父shouldComponentUpdate->父componentWillUpdate->父render->子componentWillReceiveProps->子shouldComponentUpdate->子componentWillUpdate->子render->子componentDidUpdate->父componentDidUpdate
(2)修改setState
shouldComponentUpdate->componentWillUpdate->render->componentDidUpdate
(3)forceUpdate()强制更新
componentWillUpdate->render->componentDidUpdate
重要:如图可以看到setState和forceUpdate中间少了一个shouldComponentUpdate函数是因为forceUpdate是做为强制更新跳过了shouldComponentUpdate函数控制
说明(1):shouldComponentUpdate是控制是否可被渲染的流程开关它需要返回一个boolean值。不写该函数默认为true,也可手动修改为false,当为false时页面将不重新render,
说明(2):componentWillReceiveProps函数是可以接受到props更新后的值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值