挂载
constructor
constructor(props) {
super(props);
this.state = {
text: '构造方法'
};
}
componentWillMount
componentWillMount()
render
- 检查 this.props 和 this.state 的数据并返回一个 React 元素
componentDidMount
componentDidMount()
- render方法后被执行
更新
- 当一个组件被重新渲染时,会调用如下方法。
componentWillReceiveProps
componentWillReceiveProps(nextProps) //在挂载的组件接收到新的props时被调用
shouldComponentUpdate
boolean shouldComponentUpdate(nextProps, nextState) //当组件接收到新的props和state时, shouldComponentUpdate方法默认返回true
componentWillUpdate
componentWillUpdate(nextProps, nextState)
componentDidUpdate
componentDidUpdate(prevProps, prevState) //两个参数分别是渲染前的props和渲染前的state
卸载
componentWillUnmount()
网友评论