React生命周期
React16之后将要废弃生命周期
- componentWillMount
- componentWillReceiveProps
- componentWillUpdate 保留了UNSAFE_前缀的三个函数,为了向下兼容。应避免使用
挂载阶段
- constructor:构造函数,通常在构造函数中初始化state对象或者给自定义方法绑定this
- getDerivedStateFromProps:将要
- render
- componentDidMount:组件装载之后调用,可以获取到DOM节点并操作。
更新阶段
- getDerivedStateFromProps
- shouldComponentUpdate
- render
- getSnapshotBeforeUpdate
- componentDidUpdate
卸载阶段
- componentWillUnmount