React · Senior · Question 49 of 75
What does TanStack Query give you compared to loading data in useEffect with useState?
- ✓Correct answer: Deduplication, caching, retries, background updates and race protection out of the box
- 2Only a shorter syntax; the approaches behave the same
- 3It makes requests synchronous, so loading states aren't needed
Explanation
Hand-rolled loading in an effect quickly accumulates problems: response races, no cache (refetching on every mount), duplicates from several components, manual retries and error handling, desync with the server. The library solves this declaratively via keys.