Skip to content

Instantly share code, notes, and snippets.

@ramoncardena
Last active February 19, 2019 16:59
Show Gist options
  • Save ramoncardena/3e84e676c6c4b90aff7ac0819c5eabef to your computer and use it in GitHub Desktop.
Save ramoncardena/3e84e676c6c4b90aff7ac0819c5eabef to your computer and use it in GitHub Desktop.
React 16.8 Lifecycle Methods

React 16.8 Lifecycle Methods

Reference for React components defined as classes.

Mounting Updating Unmounting
constructor()
static getDerivedStateFromProps()
render()
componentDidMount()
static getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
componentWillUnmount()

*** Executed in order from top to bottom

Mounting

Methods called when instance of component added to the DOM

  • constructor()
  • static getDerivedStateFromProps()
  • render()
  • componentDidMount()

Legacy:

  • UNSAFE_componentWillMount()

Updating

Methods called when component re-rendered (changes in props or state)

  • static getDerivedStateFromProps()
  • shouldComponentUpdate()
  • render()
  • getSnapshotBeforeUpdate()
  • componentDidUpdate()

Legacy:

  • UNSAFE_componentWillUpdate()
  • UNSAFE_componentWillReceiveProps()

Unmounting

Methods called when component removed from DOM

  • componentWillUnmount()

Error Handling

Methods called when an error ocurred during rendering, lifcicly method or child's constructor

  • static getDerivedStateFromError()
  • componentDidCatch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment