半亩花田i
平时学习的笔记以及写的demo,仅供参考
posts - 65,comments - 2,views - 94458
(一)生命周期(旧)v16.8.4(黄色底纹的新版本加UNSAFE_前缀)
1、初始化阶段:由ReactDOM.render()触发----初次渲染
constructor()
componentWillMount():组件将要挂载 。
componentDidMount():组件挂载完毕
PS:一般在这个钩子中做一些初始化的事,例如:开启定时器、发送网络请求、订阅消息。
2、更新阶段:由组件内部this.setSate()或父组件render触发
componentWillReceiveProps():组件将要接收新的props ---->组件第一次不进此钩子函数,第二次更新才进。
shouldComponentUpdate():控制组件更新的“阀门”
componentWillUpdate():组件将要更新
render()
componentDidUpdate():组件更新完毕
3、卸载组件:由ReactDOM.unmountComponentAtNode()触发
componentWillUnMount():组件将要卸载
PS:一般在这个钩子中做一些收尾的事,例如:关闭定时器、取消订阅消息。
 
(二)生命周期(新)
1、初始化阶段:由ReactDOM.render()触发----初次渲染
constructor()
getDerivedStateFromProps():若state的值任何时候都取决于props,那么可以使用该钩子。
render()
componentDidMount():组件挂载完毕
PS:一般在这个钩子中做一些初始化的事,例如:开启定时器、发送网络请求、订阅消息。
2、更新阶段:由组件内部this.sertSate()或父组件重新render触发
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate:在更新之前获取快照。
componentDidUpdate()
3、卸载组件:由ReactDOM.unmountComponentAtNode()触发
componentWillUnMount:组件将要卸载
 
组件强制更新:this.forceUpdate();
react新生命周期和旧生命周期的区别:废弃componentWillMount、componentWillReceiveProps、componentWillUpdate生命周期,新增getDerivedStateFromProps、getSnapshotBeforeUpdate生命周期。
posted on   半亩花田i  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示