react v16.3之前版本 | react v16.4开始的版本 |
挂载 当组件实例被创建并插入 DOM 中时,其生命周期调用顺序如下: | |
constructor() componentWillMount() (即将过时) render() componentDidMount() | constructor() static getDerivedStateFromProps() (新增) render() componentDidMount() |
更新 当组件的 props 或 state 发生变化时会触发更新。组件更新的生命周期调用顺序如下: | |
componentWillReceiveProps() (即将过时) shouldComponentUpdate() componentWillUpdate() (即将过时) render() componentDidUpdate() | static getDerivedStateFromProps() (新增) shouldComponentUpdate() render() getSnapshotBeforeUpdate() (新增) componentDidUpdate() |
卸载 当组件从 DOM 中移除时会调用如下方法: | |
componentWillUnmount() | componentWillUnmount() |
错误处理 当渲染过程,生命周期,或子组件的构造函数中抛出错误时,会调用如下方法: | |
-- | static getDerivedStateFromError() (新增) componentDidCatch() (新增) |
新增其他 APIs | |
-- | forceUpdate() |
react新旧版本生命周期函数对比
最新推荐文章于 2024-03-27 16:58:34 发布