react生命周期
1.初始化阶段:由ReactDOMm.render()触发---初次渲染
1.constructor
2.componentWillMount(建议弃用还能正常使用)
2.getDerivedStateFromProps
3.render
4.componentDidMount
2.更新阶段:由组件内部this.setSate()或父组件重新render触发
1.shouldComponentUpdate
2.componentWillUpdate(建议弃用还能正常使用)
3.render
4.getSnapshotBeforeUpdate(这个函数有两个入参prevProps, prevState,返回值作为参数传给componentDidUpdate,该生命周期需要搭配componentDidUpdate一起使用)
5.componentDidUpdate
3.卸载组件
componentWillUnmount
componentWillReceiveProps(建议弃用还能正常使用)
16之后有三个生命周期被废弃:
- componentWillMount
- componentWillReceiveProps
- componentWillUpdate