React · Middle · Question 67 of 75
Why is it fine to call setState inside useEffect that depends on userId to fetch data?
- ✓Correct answer: Fetching synchronizes the component with an external system (the server); just add cleanup to ignore stale responses
- 2It isn't - effects must never set state
- 3Because
userIdis a prop
Explanation
Data fetching is a legitimate effect, though frameworks and libraries (TanStack Query, RSC) handle caching and races better than manual effects.