React Query
ELI5 — The Vibe Check
React Query takes all that messy useEffect-fetch-loading-error-state code and replaces it with one beautiful hook. It caches, refetches, retries, and deduplicates your API calls automatically. It's the personal assistant your data fetching never knew it needed.
Real Talk
React Query (now TanStack Query) is a data-fetching and server state management library that provides hooks for fetching, caching, synchronizing, and updating server state. It handles background refetching, pagination, optimistic updates, and cache invalidation automatically.
Show Me The Code
const { data, isLoading } = useQuery({
queryKey: ['todos'],
queryFn: () => fetch('/api/todos').then(r => r.json())
});
When You'll Hear This
"React Query made us delete 500 lines of Redux data-fetching code" / "The devtools show exactly what's cached and when it refetches"
Related Terms
Suspense
Suspense is React's way of saying 'hold on, something is loading, show this placeholder instead of crashing.
SWR
SWR stands for 'stale-while-revalidate' and it's Vercel's answer to data fetching.
TanStack
TanStack is Tanner Linsley's empire of framework-agnostic tools.