TanStack Query
Hooks for managing, caching and synchronizing remote data in React.
3. Used by agents' projects
Dependency in 458 public GitHub projects set up for AI coding agents that we scanned (7.3%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
tanstack.com/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What TanStack Query does
TanStack Query treats server data as a cache with a four-step lifecycle (fetch, share, revalidate, collect). Components declare a key and the data they need, and the cache coordinates the fetches.
TanStack Query popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How TanStack Query is used
- TanStack Query is a dependency in 458 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (9.4% of the 4,867 JavaScript/TypeScript ones), #1 of 53 in state and data fetching.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 2,243; those are left out of every share on this page.
- The most used alternative in our scan is SWR (51 projects).
- Projects that use it most often also use Lucide React (77.5%), Tailwind Merge (74.9%), clsx (76.4%).
- It is more common in projects set up for Roo Code (14.4%) than for Gemini CLI (6.1%).
By coding agent
Often used with
TanStack Query in practice
Strengths
The site says components that ask for the same key share one cache entry. In its words, every observer reads that entry "instead of issuing another request."
Under the heading "Deadly defaults," the site lists caching, request deduplication, retries, background refetching, window-focus updates and garbage collection as already set up.
The README lists mutations, dependent queries, background updates, prefetching, cancellation and React Suspense support. It also lists pagination and infinite scroll.
TanStack publishes a root <code>llms.txt</code> that points agents to a separate docs index for each product. Query has its own index. The root file says to fetch the linked product docs index first, then follow links from there for deeper context.
Watch out for
The site says "Stale data can remain valuable" and that stale data stays visible while a background request refreshes it.
The site says data with no observers stays available "briefly" before garbage collection removes it. These pages do not say how long "briefly" is.
The site says the parts of a write "stay explicit." Its sample mutation outline shows four parts: an optimistic <code>setQueryData</code>, the awaited server call, a targeted <code>invalidateQueries</code>, and an <code>onError</code> rollback.
More about TanStack Query
Funding
- GitHub Sponsors: https://github.com/tannerlinsley
- GitHub Sponsors: https://github.com/TkDodo
- 158 GitHub sponsors
Head to head
- TanStack Query vs SWR used together in 14 projects
Packages around it
- class-variance-authority: Variant class names
- tailwind-merge: Tailwind class merging
- clsx: Conditional class names
- react: UI library
- @radix-ui: UI primitives
- lucide-react: Icons
More in State and data fetching
Alternatives
TanStack Query This page
React hooks library for data fetching with caching, revalidation and real-time updates.
Get started
Install it.
npm install @tanstack/react-queryRules for your agent
## TanStack Query
- Declare data in components with `useQuery()` and an array query key. The site's examples use keys such as `['issues', 'router-cache']` and `['issues', 'project-detail']`.
- Before writing your own request deduplication, retries, background refetching, window-focus updates or garbage collection, check the defaults. The site says these "arrive wired."
- Keep the query function to resolving data. The site says Query owns cancellation, retries and deduplication around it.
- Expect stale data to stay visible while a background request refreshes it. The site says stale data "can remain valuable."
- For optimistic updates, follow the shape of the site's sample mutation outline: `setQueryData(['todos'], next)`, then `await saveTodo(todo)`, then a targeted `invalidateQueries({ queryKey: ['todos'] })`, with a rollback path in `onError`.
- For docs, start from `https://tanstack.com/llms.txt`. It links the Query docs index at `https://tanstack.com/query/latest/llms.txt`. The root file says to fetch the linked product docs index first and follow links from that page only when you need deeper context.