React · Middle · Question 67 of 75

Why is it fine to call setState inside useEffect that depends on userId to fetch data?

Explanation

Data fetching is a legitimate effect, though frameworks and libraries (TanStack Query, RSC) handle caching and races better than manual effects.

Further reading

Problem with a question

React · Middle · question 67

Test yourself

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

Take this quiz