Open lznbuild opened 4 years ago
getDefaultProps(首次挂载执行,重新挂载不执行)
constructor
getInitialState
当使用class组件构建React组件时,static defaultProps={}就是调用了内部的getDefaultProps方法,constructor中的this.state={}就是调用内部的getInitialState方法。
componentWillMount
render
componentDidMount
componentWillReceiveProps(nextProps) // 调用setState不会二次渲染
shouldComponentUpdate(nextProps, nextState) // 返回false,不再执行以下方法
componentWillUpdate(nextProps, nextState) // no setState
componentDidUpdate(prevProps, prevState)
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
componentWillUnmount //一般用于执行一些清理方法,如事件回收或是清除定时器
getDefaulProps
getDerivedStateFromProps
(props,state更新) getDerivedStateFromProps
getSnapsHotBeforeUpdate
componentDidCatch
React 16之前的
初始阶段
getDefaultProps(首次挂载执行,重新挂载不执行)
constructor
getInitialState
当使用class组件构建React组件时,static defaultProps={}就是调用了内部的getDefaultProps方法,constructor中的this.state={}就是调用内部的getInitialState方法。
组件挂载阶段
componentWillMount
render
componentDidMount
组件更新过程
props更新
componentWillReceiveProps(nextProps) // 调用setState不会二次渲染
shouldComponentUpdate(nextProps, nextState) // 返回false,不再执行以下方法
componentWillUpdate(nextProps, nextState) // no setState
render
componentDidUpdate(prevProps, prevState)
state更新
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
组件卸载阶段
componentWillUnmount //一般用于执行一些清理方法,如事件回收或是清除定时器
React 16之后的
初始阶段
constructor
getDefaulProps
getInitialState
挂载阶段
getDerivedStateFromProps
render
componentDidMount
更新阶段
(props,state更新) getDerivedStateFromProps
shouldComponentUpdate
render
getSnapsHotBeforeUpdate
componentDidUpdate
错误处理
componentDidCatch