一、生命周期钩子简单描述
React 生命周期
//挂载部分
1.constructor添加状态 以及 事件处理函数绑定this
2.render 返回组件模板
3.conponentDidMount()是在组件已经被渲染到 DOM 中后运行,在这里挂定时器
//更新部分
4.shouldComponentUpdate()性能优化
5.render
6.getSnapshotBeforeUpdate()
7.componentDidUpdate组件更新后执行
8.卸载 componentWillUnmount() 组件卸载前执行 清理垃圾
二、生命周期钩子的简单使用
class LifeCircle extends Component
{
constructor(props){
super(props);
}
render(){
return <div>
hello world
</div>
}
conponentDidMount(){
console.log('vconponentDidMount');
}
}
class LifeCircle extends Component
{
constructor(props){
super(props);
}
render(){
return <div>
hello world
</div>
}
componentWillUnmount(){
console.log('componentWillUnmount');
}
}
class LifeCircle extends Component
{
constructor(props){
super(props);
}
render(){
return <div>
hello world
</div>
}
componentWillUnmount(){
console.log('componentWillUnmount');
}
}
三、注意有返回值的钩子
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuoyibo.net 版权所有 湘ICP备2023021910号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务