Skip to content

tanstack-query

Use when managing server state with TanStack Query (React Query) — data fetching, caching, mutations, optimistic updates, or infinite scrolling. Also use when replacing manual useEffect data fetching or integrating with tRPC.

ModelSource
sonnetpack: state
Full Reference

┏━ 🔧 tanstack-query ━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Use when managing server state with TanStack Q… ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Async state management for TypeScript/React. Replaces useEffect + useState for all server state with automatic caching, background refetching, and deduplication. v5.x requires React 18+ and TypeScript 4.7+.

ItemValue
Installnpm install @tanstack/react-query
DevToolsnpm install -D @tanstack/react-query-devtools
Versionv5.x
Key importsuseQuery, useMutation, useQueryClient, useInfiniteQuery
Docshttps://tanstack.com/query/latest
I want to…File
Install, configure QueryClient, and set up the providerreference/setup.md
Fetch data, use query options, write dependent queries, or cancel requestsreference/queries.md
Create, update, or delete data with useMutationreference/mutations.md
Implement optimistic updates — variables-based or cache manipulationreference/optimistic-updates.md
Paginate results or build infinite scrollreference/infinite-queries.md
Configure staleTime, gcTime, prefetching, or SSR hydrationreference/caching.md
Use Suspense mode with useSuspenseQueryreference/suspense.md
Set up DevTools or write tests for queries and mutationsreference/devtools.md

Usage: Read the reference file matching your current task from the index above. Each file is self-contained with code examples and inline gotchas.