前言:React中组件有生命周期,在16.3版本之后,我们把生命周期分为四个阶段:初始化、运行中、销毁和错误处理。值得注意的是,生命周期的钩子一定不要写成箭头函数!
一、15版本的钩子
getDefaultProps()
(16版本已弃用)getInitialState()
(16版本已弃用)componentWillMount()
render()
componentDidMount()
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
componentDidUpdate()
componentWillMount()
流程详见下图:
二、16版本的钩子
constructor()
(较15版本新增)componentWillMount()
(17版本已弃用)render(