TanStack Query
A standalone library for fetching, caching and updating server state.
Query keys, stale times, mutations, invalidation, infinite queries and SSR hydration, in React, Vue, Solid and more.
State & data fetching
Both cache server data, dedupe requests and refetch in the background. TanStack Query is standalone and framework-agnostic; RTK Query is built into Redux Toolkit and stores its cache in the Redux store.
A standalone library for fetching, caching and updating server state.
Query keys, stale times, mutations, invalidation, infinite queries and SSR hydration, in React, Vue, Solid and more.
Redux Toolkit's data fetching and caching layer.
Endpoints defined in createApi generate hooks; cache lives in Redux with tag-based invalidation.
| Aspect | TanStack Query | RTK Query |
|---|---|---|
| Requires Redux | No | Yes |
| Definition style | Per-call query keys | Central API with endpoints |
| Invalidation | Query keys | Tags |
| Frameworks | React, Vue, Solid, Svelte, Angular | React (and any Redux app) |
| Best for | Most apps | Apps already on Redux Toolkit |
Both fetch, cache and keep server data fresh. TanStack Query is a standalone library you use per call with query keys, in React and other frameworks. RTK Query is part of Redux Toolkit: you define an API with endpoints, it generates hooks, and its cache lives in the Redux store.
No. TanStack Query only needs a QueryClient and QueryClientProvider. RTK Query requires a Redux store configured with its reducer and middleware.
TanStack Query invalidates by query key, for example invalidateQueries({ queryKey: ['todos'] }), refetching matching queries. RTK Query uses tags: queries provide tags and mutations invalidate them, so related queries refetch.
When the app already uses Redux Toolkit and you want server data in the same store and DevTools, with a centralised API definition and generated hooks per endpoint.
For most new apps, apps without Redux, apps using several frameworks, or when you want fine-grained control of caching per query and a large ecosystem of patterns.
TanStack Query: useQuery({ queryKey, queryFn }) wherever you need data, with keys and fetchers defined at the call site or in helper functions. RTK Query: createApi with endpoints in one place, generating hooks like useGetTodosQuery.
TanStack Query uses staleTime to decide when data needs refetching and gcTime for how long unused data stays cached. RTK Query uses keepUnusedDataFor and refetch options such as refetchOnMountOrArgChange.
TanStack Query's useMutation runs a mutation function with onMutate, onSuccess and onError callbacks. RTK Query mutations are endpoints with builder.mutation that invalidate tags automatically on success.
TanStack Query: in onMutate, cancel queries, set new data with setQueryData and roll back on error. RTK Query: in onQueryStarted, call updateQueryData to patch the cache and undo on failure.
Both deduplicate identical in-flight requests: multiple components asking for the same key or endpoint and arguments share one network request.
Practise every comparison in your dashboard.
Start learning