生命周期
三个状态:
Mounting:已插入真实(挂载)
Updating:正在被重新渲染
Unmounting:已移除真实DOM(卸载)
react为每个状态提供了两种处理函数,will函数在进入状态之前,did函数在进入状态之后
- componentWillMount()
- componentDidMount()
- componentWillUpdate(object nextProps, object nextState)
- componentDidUpdate(object prevProps, object prevState)
- componentWillUnmount()
两种特殊的状态
componentWillReceiveProps(object nextProps) 已加载组件收到新的参数时使用
shouldComponentUpdae(object nextProps,object nextState) 判断组件是否重新渲染时使用
文档上
Mounting
constructor() 组件的构造函数在组件mount之前被调用
componentWillMount
render()
componentDidMount()
Updating
componentWillReceiverProps()
shouldComponentUpdate() 判断组件是否重新渲染时使用,当返回false时不会调用render()
componentWillUpdate()
render()
componentDidUpdate()
Unmouting
componentWillUnmount()