React中内部组件生命周期的运行方式。html
类调用:
此过程仅在类建立时被一次,即不管建立多少个ReactElement,此过程均只会执行一次函数
getDefaultProps测试
实例化:
此过程仅执行一次,执行完毕后,React组件真正被渲染到DOM中
期间执行生命周期函数以下:this
getInitialStatespa
componentWillMountcode
rendercomponent
componentDidMounthtm
变动 blog
此过程会在this.state
或this.props
变动时执行
期间执行生命周期函数以下:生命周期
this.state
变动
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
this.props
变动
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
卸载
此过程在组件销毁前调用一次期间执行生命周期函数以下:
componentWillUnmount
整个生命周期所涉及的方法如图所示:
<Super> <Sub_1 /> <Sub_2 /> </Super>