React的生命周期

React中组件也有生命周期,也就是说也有很多钩子函数供我们使用, 组件的生命周期,我们会分为四个阶段,初始化、运行中、销毁、错误处理(16.3之后)

1、初始化

在组件初始化阶段会执行

  1. constructor

  2. static getDerivedStateFromProps()

  3. componentWillMount() / UNSAFE_componentWillMount()

  4. render()

  5. componentDidMount()

2、更新阶段

propsstate的改变可能会引起组件的更新,组件重新渲染的过程中会调用以下方法:

  1. componentWillReceiveProps() / UNSAFE_componentWillReceiveProps()

  2. static getDerivedStateFromProps()

  3. shouldComponentUpdate()

  4. componentWillUpdate() / UNSAFE_componentWillUpdate()

  5. render()

  6. getSnapshotBeforeUpdate()

  7. componentDidUpdate()

3、卸载阶段

  1. componentWillUnmount()

4、错误处理

  1. componentDidCatch()

https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/

这里给大家一个网址可以查看一下React生命周期的图解,想了解React各大生命周期的详解请关注博主的下一条文章 谢谢大家的浏览

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值