Put in order · JavaScript and React course · Module 5: useEffect and Custom Hooks

Lifecycle of the Cleanup Function in useEffect

Order the stages of the effect lifecycle with a cleanup function:

Items to put in order

  • React runs the new effect with current values
  • State changes - a re-render occurs
  • Component unmounts - React calls the final cleanup
  • React calls cleanup from the previous effect
  • Component renders - useEffect runs the effect

You can check the correct answer by solving this task in the CodeWorlds game.