Skip to content

Instantly share code, notes, and snippets.

@matt-winzer
Last active February 20, 2018 23:29
Show Gist options
  • Save matt-winzer/f562f7e4a04103b51027184c38af6f70 to your computer and use it in GitHub Desktop.
Save matt-winzer/f562f7e4a04103b51027184c38af6f70 to your computer and use it in GitHub Desktop.

React Component Lifecycle

Objectives

  • What are lifecycle methods?
  • Which ones can/should we use?
  • Which methods/hooks are most important?

Notes

  • What are lifecycle methods?

    • Moments in a component's life that allow you to perform actions
    • Needs to be a class component to use them!
    • Methods that EVERY component has
      • But doesn't HAVE to be 'used'
  • Which ones can/should we use?

  • Which methods/hooks are most important?

    • componentDidMount() !!!!!

      • Means component has been added to the DOM
      • Make your requests for DATA here => (AJAX requests)
    • render() !!!!!!

      • allows you to template using JSX
    • constructor()

      • Not always necessary
    • componentWillMount()

      • Not as important as it used to be
      • Specific use cases (server-side rendering)
        • 'This is the only lifecycle hook called on server rendering.'
      • AVOID making AJAX calls here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment