Async Data Fetching with React Query / TanStack Query
Learn how server-state libraries like TanStack Query handle caching, background refetching, and deduplication that plain useEffect fetching doesn't.
TanStack Query (formerly React Query) is built on the recognition that server state — data owned by a remote source and merely cached on the client — has fundamentally different needs than client state like form inputs or UI toggles. It can go stale, needs refetching, may be requested by multiple components simultaneously, and benefits from caching across navigations.
TanStack Query is like a well-run reference desk at a library: if five people ask for the same book (same query key) at once, the librarian fetches it a single time and hands a copy to everyone, keeps a recently-used shelf (cache) so the next request doesn't need a fresh trip to the stacks, and periodically checks if a newer edition (background refetch) has come out.