Question · JavaScript and React course · Module 5: useEffect and Custom Hooks

Cleanup Function in useEffect

When does the cleanup function returned from useEffect execute?

Answer options

  • Only during the first render of the component
  • Before each re-execution of the effect and when the component unmounts
  • Only after clicking a button in the component
  • Never - the cleanup function is ignored by React

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