Mounting/组件初始化相关

componentWillMount
componentDidMount

Updating/组件更新相关

componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
componentDidUpdate

Unmounting/组件移除相关

componentWillUnmount

Initial 相关

getDefaultProps
getInitialState

componentWillMount

在组件初始化前执行, 但仅执行一次, 即使多次重复渲染该组件,或者改变组件的 state
如果希望该回调能执行多次, 可以使用 React.unmountComponentAtNode 移除已有的组件, 然后重新 render

componentDidMount

在组件初始化完成时触发, 同样只能触发一次

componentWillReceiveProps

在组件接收到新的 props 的时间点之前调用, 注意初始化的时候不会触发(此时初始化 props, 而不是获得新的 props), 但是如果组件重复渲染(没有移除), 则会触发此事件

shouldComponentUpdate

组件接收到新的 props 或 state 的时候(此时还没进行下一次 render) 会立即调用, 然后通过返回布尔值决定是否要重新渲染当前组件
该接口接收两个参数, 第一个参数表示新的props, 第二个表示新的 state

shouldComponentUpdate:function(){return true} //重新渲染组件

componentWillUpdate

shouldComponentUpdate 返回 true 的时候调用, 此时 props 和 state 都是更新后的值, 而组件尚未重新渲染

componentDidUpdate

重新渲染后才会触发

componentWillUnmount

组件被移除之前触发, 用于做一些必要的清理, 比如无效的定时器等

getDefaultProps

该方法是最先触发的, 可以在该方法中 return 一个对象作为组件的默认 Props(当然如果有从父组件传来的 props, 则以传进来的为主)
只在组件初始化的时候执行一次

getInitialState