goldEli / Front-End-Training

Front End Training
2 stars 5 forks source link

React 生命周期对应的方法 #67

Open goldEli opened 4 years ago

goldEli commented 4 years ago

React 生命周期对应有哪几个方法,每个方法怎么用?

lurasso commented 4 years ago
初始化阶段:
1、defaultProps 设置组件默认属性
2、constructor 设置组件的初始化状态
3、componentWillMount() 组件即将被渲染时被触发
4、render() 渲染时触发
5、componentDidMount() 渲染完成后,此时可以操作dom元素
运行中阶段:
1、componentWillReceiveProps() 属性接收到属性后触发,可以通过修改父组件的属性值调用该函数
2、shouldComponentUpdate() 当组件接收到新属性,或者组件的状态发生改变时触发,可以在这个函数优化性能
3、componentWillUpdate() 组件即将被更新时触发
4、componentDidUpdate() 组件完成更新后触发
卸载阶段:
1、componentWillUnmount() 组件被销毁时触发,可用于清理定时器和取消redux订阅
FireDragonZL commented 4 years ago