Question · JavaScript and React course · Module 11: Data Fetching and APIs

Cleanup in useEffect with AbortController

When does React call the cleanup function (return) from useEffect?

Answer options

  • Only when the entire application shuts down
  • Before each re-run of the effect (dependency change) and when the component unmounts
  • Only on the first render of the component
  • Never - cleanup must be called manually

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