0
Challenge · 64Architecture & State
TanStack Query
Ecoused in ~70% of apps
Every screen that hand-rolls fetch-in-useEffect re-implements loading flags, error handling, race guards, caching and refetching — and ships subtle bugs each time. TanStack Query is the library that does all of it once, correctly, for your whole app. In 2026 it is the default way to talk to a server from React, and interviewers expect you to know why.
Core idea. TanStack Query is an async-state manager, not a fetch library: you give useQuery a queryKey (the cache id) and a queryFn (how to fetch), and it returns { data, isPending, isError, error } while handling caching, deduplication, background refetching and stale-while-revalidate for you — useMutation writes, then invalidateQueries marks the affected keys stale so they refetch.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
query cachequeryKey: ['posts']
EMPTY
no cached data — first observer will fetch
<Sidebar/>useQuery(['posts'])
unmounted — not subscribed
<Feed/>useQuery(['posts'])
unmounted — not subscribed
network & cache log
Mount <Sidebar/> then <Feed/> quickly — both share
['posts'] so the second one dedupes onto the first request.One queryKey = one cache entry shared by every component. Two observers dedupe to a single request; a fresh cache serves data instantly; a mutation invalidates the key so it refetches in the background and every consumer updates at once.
↑ play a little first, then dig in