React V7版本一些新的生命周期函数
Mount阶段:
- constructor()
- static getDerivedStateFromPro ps():返回一个对象来更新 state,如果返回 null 则不更新任何内容。(componentWillMount() / UNSAFE_componentWillMount()//被废弃)
- render()
- componentDidMount()
Update阶段:
(componentWillReceiveProps() / UNSAFE_componentWillReceiveProps()//被废弃)
- static getDerivedStateFromProps()
- shouldComponentUpdate()
(componentWillUpdate() / UNSAFE_componentWillUpdate()//被废弃)
- render()
- getSnapshotBeforeUpdate():返回值将传给componentDidUpdate()的第三个参数 ,否则第三个参数将为undefined。
- componentDidUpdate()
Unmount阶段:
- componentWillUnmount()
图例更清晰:
捕获错误的生命周期函数
- static getDerivedStateFromError():在后代组件抛出错误后被调用。
- componentDidCatch():在后代组件抛出错误后被调用。
还没有评论,来说两句吧...