# TanStack Query — card for AI agents

Hooks for managing, caching and synchronizing remote data in React.

Category: State and data fetching · npm package `@tanstack/react-query` · latest version 5.105.0 (checked 2026-11-01)
Install: `npm install @tanstack/react-query`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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.

## Docs written for agents
- [llms.txt (index of the docs)](https://tanstack.com/llms.txt)

## What it is
- TanStack Query is a library for data that comes from a server. The README calls it "an async state management library built to simplify fetching, caching, synchronizing, and updating server state." The GitHub repository was created on 2019-09-10 and is MIT licensed. The repository description mentions React Query, Solid Query, Svelte Query and Vue Query. It does not mention Angular, Preact or Lit.
- The website describes the model as giving async data "a cache, a lifecycle, and declarative APIs." A component calls `useQuery()` with an array key such as `['issues', 'router-cache']`. The site then lays out four steps: fetch, share, revalidate, collect. Writes go through mutations. The site's outline updates the cache with `setQueryData` and refreshes it with `invalidateQueries`.
- TanStack's root `llms.txt` has an entry for Query that lists React, Preact, Solid, Vue, Svelte, Angular and Lit as frameworks. It lists `@tanstack/query-core` and `react-query` as packages. The site pitches the library as "the server-state standard for modern frontend apps." Everything on this page comes from TanStack's own pages. The sources include no reports from projects built with it.

## Caveats
- Stale values stay on screen during a refresh: The site says "Stale data can remain valuable" and that stale data stays visible while a background request refreshes it.
- Unused entries are removed, timing not stated here: The site says data with no observers stays available "briefly" before garbage collection removes it. These pages do not say how long "briefly" is.
- Writes are explicit: The site says the parts of a write "stay explicit." Its sample mutation outline shows four parts: an optimistic `setQueryData`, the awaited server call, a targeted `invalidateQueries`, and an `onError` rollback.
- No single full-docs file for agents: The root `/llms-full.txt` returns only the index, not the full docs. TanStack says this is intentional because the complete docs corpus is too large for a useful root-level context file.

## Numbers (AgentGid data)
- Gid Score: 88.1 (#15 of all tools, 2 of 53 in its category)
- Used in 458 public projects set up for AI coding agents (7.3%)
- Downloads last week: 91,971,702 (as of 2026-11-24), +31.3% over 4 weeks
- GitHub stars: 50,624 (as of 2026-11-24)
- Last push: 2026-11-24

## Often used with
Lucide React 77.5%, Tailwind Merge 74.9%, clsx 76.4%, React 98.5%, Class Variance Authority 70.5%, Radix UI 62.2%

## Checked alternatives (same job)
- SWR: https://agentgid.com/tools/swr/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/tanstack-react-query/
- Homepage: https://tanstack.com/query
- Repository: https://github.com/TanStack/query
- Source: https://github.com/TanStack/query#readme
- Source: https://github.com/TanStack/query
- Source: https://github.com/TanStack/query/releases
- Source: https://tanstack.com/query
- Source: https://tanstack.com/llms.txt

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
