Query vs RTK Query

TanStack Query Versus Redux Toolkit Query

RTK Query is the data-fetching layer inside Redux Toolkit 3,824 (@reduxjs/toolkit 2.12.0, MIT). You describe an API once with createApi({ baseQuery, endpoints }), and it generates hooks such as useGetBookQuery(3) and useToggleFavoriteMutation(). Both libraries solve the same problem; they differ in where the cache lives and how it is invalidated:

TanStack Query 79,069 and RTK Query compared
TanStack Query 5 RTK Query (Redux Toolkit 2)
Cache lives in Its own QueryClient The Redux 3,824 store, visible in Redux DevTools 14,368
Defined by Query keys and functions at the call site Endpoints declared up front in createApi
Invalidation By key prefix (invalidateQueries) By tags (providesTags, invalidatesTags)
React Native 36,878 focus and online focusManager, onlineManager setupListeners with your own handlers
Needs Nothing else Redux store and react-redux

Choose RTK Query if the app already uses Redux: the data sits in the same store, and endpoints can be generated from an OpenAPI description with @rtk-query/codegen-openapi. Choose TanStack Query otherwise: it adds no global store, its keys work with any fetching code (REST, GraphQL, Firebase 1 , a native module), and its offline and persistence plugins are more complete. SWR 639 (https://github.com/vercel/swr 32,494 ), from Vercel 3,061 , is a lighter third option with fewer features for mutations and offline use. All three are open source and free.