React lifecycle cheatsheet

January 11, 2017 · View on GitHub

React lifecycle cheatsheet

MethodSide effects1State updates2Example uses
Mounting
componentWillMountConstructor equivalent for createClass
renderCreate and return element(s)
componentDidMountDOM manipulations, network requests, etc.
Updating
componentWillReceivePropsUpdate state based on changed props
shouldComponentUpdateCompare inputs and determine if render needed
componentWillUpdateSet/reset things (eg cached values) before next render
renderCreate and return element(s)
componentDidUpdateDOM manipulations, network requests, etc.
Unmounting
componentWillUnmountDOM manipulations, network requests, etc.

For more information see here.

  1. "Side effects" refer to modifying variables outside of the instance, async operations, etc.
  2. "State updates" refer to the current instance only (eg this.setState).