Skip to content

Instantly share code, notes, and snippets.

@coreyar
Forked from jcreamer898/react-lifecycle.md
Last active February 22, 2018 14:54
Show Gist options
  • Save coreyar/18ad4eee709a0f6020f52e29e90a57ce to your computer and use it in GitHub Desktop.
Save coreyar/18ad4eee709a0f6020f52e29e90a57ce to your computer and use it in GitHub Desktop.
Name of thing Sorta like... Mounted? Can you even setState? What would you say... ya do here?
constructor(props) initialize() nope nope init stuff NO side effects
componentWillMount() beforeDomReady() nope yeah but don't Only needed in createClass now use constructor for most things
render render nope please no render stuff and don't set any state please
componentDidMount() domReady() yup yup DOM is a go init jQuery plugins dispatch stuff
componentWillReceiveProps(nextProps) onChange() yup yup Props changed feel free to update state if needed
componentWillUpdate(nextProps, nextState) beforeRender() yup nope The props or state changed need to do anything else before rendering?
shouldComponentUpdate(nextProps, nextState) shouldRender() yup nope So yeah something changed but do we REALLY need to update?
componentDidUpdate(prevProps, prevState) afterRender() yup yup Great success we've rendered a thing... anything else?
componentWillUnmount() destroy() too late too late Only you can prevent memory leaks aka unbind things
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment