react 生命周期函数

1~
初始化 constructor
将要挂载 componentWillMount
渲染 render
挂载 componentDidMount
是否要更新 shouldComponentUpdate
当数据发生改变 触发生命周期函数 这个时候分两种状态
是否存在 shouldComponentUpdate 这个函数
第一个 不存在 数据正常更新
触发 三个函数:
将要更新 componentWillUpdate 渲染 render 更新 componentDidUpdate
第二个 存在 数据被拦截
按照你自己的需求去返回true 或者false,这个函数存在必须要返回相关的布尔值, 否则报错
这个函数方法有两个参数 第一个 newProps 第二个是 newState
如果是true的时候
生命周期的顺序是
shouldComponentUpdate是否要更新-》componentWillUpdate将要更新=》
render渲染-》componentDidUpdate更新
如果是false 就结束了
只走了shouldComponentUpdate-----是否要更新
将要更新 componentWillUpdate
更新 componentDidUpdate
在React中 从挂载开始 react 页面一进入会触发
初始化 constructor-》将要挂载 componentWillMount-》渲染 render-》
挂载 componentDidMount

2 ~
shouldComponentUpdate 是做什么的?
是否要更新shouldComponentUpdate
当数据发生改变 触发生命周期函数 这个时候分两种状态
是否存在 shouldComponentUpdate 这个函数
第一个 不存在 数据正常更新
触发 三个函数:
将要更新 componentWillUpdate 渲染 render 更新 componentDidUpdate
第二个 存在 数据被拦截
按照你自己的需求去返回true 或者false,这个函数存在必须要返回相关的布尔值, 否则报错
这个函数方法有两个参数 第一个 newProps 第二个是 newState
①如果是true的时候
生命周期的顺序是
shouldComponentUpdate是否要更新-》componentWillUpdate将要更新=》
render渲染-》componentDidUpdate更新
②如果是false 就结束了
只走了shouldComponentUpdate-----是否要更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值