{"schemaVersion":"1.0","record":{"label":"TanStack Query","description":"Open-source server-state library for fetching, caching and synchronizing asynchronous data with configurable query lifecycles.","aliases":["React Query"],"kind":"software","website":"https://tanstack.com/query","overview":"TanStack Query, formerly React Query, is an open-source library for managing asynchronous server state in application interfaces. It tracks fetched data, loading and error states and cache lifecycles around application-supplied query functions. It can replace repeated fetching and synchronization code, but it does not supply the backend or make cached data automatically authoritative.","license":"MIT","lifecycle":"active","example":false,"features":[{"name":"Server-state caching","status":"supported","detail":"Tracks asynchronous results by query key and exposes loading/error/data states.","useCase":"Fetching and caching server data in application interfaces","platforms":["Web applications; React adapter documentation inspected"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server state and basic React query workflow","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-keys","locator":"Changing query dependencies belong in keys","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"}]},{"name":"Controlled cache freshness","status":"supported","detail":"staleTime controls freshness while gcTime concerns inactive retention; static is stricter than Infinity.","useCase":"Fetching and caching server data in application interfaces","platforms":["Web applications; React adapter documentation inspected"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/important-defaults","locator":"Staleness, refetching, static/Infinity and garbage collection","retrievedAt":"2026-10-07T23:14:06Z","kind":"vendor"}]},{"name":"Automatic HTTP error recognition for any fetcher","status":"limited","detail":"Query functions must throw or reject; native fetch status failures require explicit handling.","useCase":"Fetching and caching server data in application interfaces","platforms":["Web applications; React adapter documentation inspected"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-functions","locator":"Rejected promises, undefined and fetch status handling","retrievedAt":"2026-10-07T23:15:27Z","kind":"vendor"}]},{"name":"Network cancellation","status":"limited","detail":"Consume the supplied AbortSignal to cancel supported requests; the guide excludes Suspense query hooks.","useCase":"Fetching and caching server data in application interfaces","platforms":["Web applications; React adapter documentation inspected"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation","locator":"AbortSignal consumption and Suspense limitations","retrievedAt":"2026-10-07T23:15:11Z","kind":"vendor"}]},{"name":"SSR hydration","status":"supported","detail":"Prefetching and hydration are documented, with per-request cache isolation required.","useCase":"Fetching and caching server data in application interfaces","platforms":["Web applications; React adapter documentation inspected"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/ssr","locator":"Request-scoped QueryClient and hydration","retrievedAt":"2026-10-07T23:14:37Z","kind":"vendor"}]}],"alternatives":[],"slug":"tanstack-query","draftAlternatives":[{"targetSlug":"swr","status":"limited","detail":"Can replace SWR for React server-data fetching and caching after adapting keys, query functions and refresh policies. Cache defaults, mutation integration and cancellation are not interchangeable APIs.","useCase":"Fetching and caching server data in application interfaces","platforms":["Web applications; React adapter documentation inspected"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server state and basic React query workflow","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/important-defaults","locator":"Staleness, refetching, static/Infinity and garbage collection","retrievedAt":"2026-10-07T23:14:06Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-functions","locator":"Rejected promises, undefined and fetch status handling","retrievedAt":"2026-10-07T23:15:27Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/getting-started","locator":"Key/fetcher and React data-fetching hook","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"}]}],"evidence":[{"url":"https://github.com/TanStack/query/blob/main/LICENSE","locator":"MIT terms","retrievedAt":"2026-10-07T23:14:37Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server state and basic React query workflow","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/important-defaults","locator":"Staleness, refetching, static/Infinity and garbage collection","retrievedAt":"2026-10-07T23:14:06Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-keys","locator":"Changing query dependencies belong in keys","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-functions","locator":"Rejected promises, undefined and fetch status handling","retrievedAt":"2026-10-07T23:15:27Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation","locator":"AbortSignal consumption and Suspense limitations","retrievedAt":"2026-10-07T23:15:11Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/ssr","locator":"Request-scoped QueryClient and hydration","retrievedAt":"2026-10-07T23:14:37Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/getting-started","locator":"Key/fetcher and React data-fetching hook","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"}],"document":{"version":1,"references":[{"url":"https://github.com/TanStack/query/blob/main/LICENSE","locator":"MIT terms","retrievedAt":"2026-10-07T23:14:37Z","id":"license","title":"TanStack Query license","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server state and basic React query workflow","retrievedAt":"2026-10-07T23:13:58Z","id":"overview","title":"TanStack Query overview","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/important-defaults","locator":"Staleness, refetching, static/Infinity and garbage collection","retrievedAt":"2026-10-07T23:14:06Z","id":"defaults","title":"TanStack Query defaults","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-keys","locator":"Changing query dependencies belong in keys","retrievedAt":"2026-10-07T23:15:02Z","id":"keys","title":"TanStack query keys","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-functions","locator":"Rejected promises, undefined and fetch status handling","retrievedAt":"2026-10-07T23:15:27Z","id":"functions","title":"TanStack query functions","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation","locator":"AbortSignal consumption and Suspense limitations","retrievedAt":"2026-10-07T23:15:11Z","id":"cancel","title":"TanStack query cancellation","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/guides/ssr","locator":"Request-scoped QueryClient and hydration","retrievedAt":"2026-10-07T23:14:37Z","id":"ssr","title":"TanStack server rendering","kind":"vendor"},{"url":"https://swr.vercel.app/docs/getting-started","locator":"Key/fetcher and React data-fetching hook","retrievedAt":"2026-10-07T23:13:58Z","id":"swr","title":"SWR getting started","kind":"vendor"}],"overviewCitations":["overview","functions"],"licenseCitations":["license"],"sections":[{"id":"scope","heading":"Server state rather than every application state","paragraphs":[{"id":"scope-detail","content":[{"text":"The library addresses data obtained asynchronously from another system, where the displayed copy can become stale independently of local UI actions. A QueryClient and provider coordinate the React integration, while query functions perform the actual work. This separates cache and request lifecycle handling from the backend transport. It should not be read as a replacement for authentication, a database or all local component state."}],"citations":["overview"]}]},{"id":"keys","heading":"Cache identity is part of correctness","paragraphs":[{"id":"keys-detail","content":[{"text":"Query keys identify the data being fetched and act as dependencies. The guide says to include changing variables used by the query function, such as the selected record or filter. Object-property order is normalized in hashing, while array order matters. A generated interface that changes its request parameters without changing its key can therefore have the wrong cache identity even when the request function looks correct."}],"citations":["keys"]}]},{"id":"defaults","heading":"Freshness and retention are different settings","paragraphs":[{"id":"defaults-detail","content":[{"text":"Cached data is stale by default, and stale queries may refetch on mounting, window focus or reconnection. staleTime changes that freshness behavior; inactive-cache retention is controlled separately by gcTime. The documented defaults include five-minute inactive retention and retry behavior. Infinity still permits manual invalidation, whereas static blocks invalidation-triggered refetches. These distinctions should be chosen for the resource rather than used as interchangeable ways to silence network activity."}],"citations":["defaults"]}]},{"id":"errors","heading":"The query function defines failure","paragraphs":[{"id":"errors-detail","content":[{"text":"A successful query must resolve data other than undefined; null can represent an intentionally empty result. To enter the error state, its function must throw or return a rejected promise. Native fetch does not throw simply because an HTTP response is unsuccessful, so the guide checks the status and throws explicitly. This boundary is useful when reviewing generated fetchers that otherwise parse an error response as successful data."}],"citations":["functions"]}]},{"id":"cancellation","heading":"Cancellation needs transport cooperation","paragraphs":[{"id":"cancellation-detail","content":[{"text":"TanStack Query supplies an AbortSignal to the query function, but an unused query's in-flight promise is not cancelled by default merely because its component unmounts. Passing the signal to a supported transport allows actual cancellation and restores prior query state. The documentation excludes the Suspense query hooks from this cancellation behavior. A cancel button should therefore be checked against the chosen hook and transport, not inferred from the presence of a library method."}],"citations":["cancel"]}]},{"id":"ssr","heading":"Server rendering and data separation","paragraphs":[{"id":"ssr-detail","content":[{"text":"The SSR guide describes prefetching, serializing the cache and hydrating it on the client. It warns against a file-level shared QueryClient that would mix data across server requests and users. Request-scoped cache creation is consequently a privacy and correctness requirement in that setup, not just a performance preference. The article does not claim a particular application's hydration or user isolation has been tested."}],"citations":["ssr"]}]},{"id":"fit","heading":"License and substitution","paragraphs":[{"id":"fit-detail","content":[{"text":"TanStack Query is MIT-licensed. It can replace "},{"text":"SWR","targetSlug":"swr"},{"text":" for suitable React data-fetching and caching workflows, with an explicit migration of keys, request functions and refresh policy. No drop-in API compatibility, benchmark or tested application migration is claimed. Applications still need their own decisions about invalidation and backend success."}],"citations":["license","overview","swr","functions"]}]}]},"id":"Q933","revision":981,"updatedAt":"2026-10-13T15:59:07Z","sourceUrl":"https://substitutefor.net/entities/Q933?revision=981"}}