react生命周期

首先说下为什么不能在render函数中调用this.setState:

render函数是一个纯函数,完全根据this.state和this.props来决定返回的结果,而且不要产生任何副作用,纯函数不应该引起状态的改变。

  • componentWillReceiveProps
  • shouldComponentUpdate
  • componentWillUpdate
  • render
  • componentDidUpdate

当props或state被修改时,就会引起组件的更新过程。