React · Junior · Question 26 of 75

When is the function returned from useEffect called?

Explanation

The cleanup function undoes what the effect set up: it unsubscribes from events, clears timers, cancels requests. React calls it before the next run of the effect with new dependencies and when the component is removed.

Further reading

Problem with a question

React · Junior · question 26

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz