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

Cleanup Function in useEffect

Order the effect lifecycle with cleanup when dependencies change:

Items to put in order

  • New effect is executed with current values
  • Cleanup of the previous effect is called
  • First render - effect is executed
  • Unmounting - final cleanup is called
  • Dependency changes - React schedules re-execution of the effect

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