TanStack Query
A library that fetches, caches and refreshes server data in frontend apps, and runs changes to it as mutations.
In more detail
Each piece of data is cached under a query key; invalidating a key makes the library refetch it. Mutations have lifecycle callbacks such as onMutate, onError and onSettled, which are the hooks for optimistic updates and rollback.
Related terms
- query key — The array that names a piece of cached server data in TanStack Query, such as ["users", "detail", "10"].
- cache invalidation — Marking cached copies as out of date, or deleting them, when the real data changes so the next read fetches fresh data.
- mutation — A change to data, and in TanStack Query or tRPC specifically, a request that creates, updates or deletes data on the server.
- optimistic update — Showing the result of a user’s action on screen immediately, before the server confirms it, and undoing it if the server says no.
- cache — A store of earlier answers kept close to where they are needed so they can be reused instead of fetched or computed again.
- cache key — The name a cache entry is saved and looked up under, usually built from the operating system and a hash of the lock file.
- SWR — A React data-fetching library from Vercel, named after the stale-while-revalidate strategy: show cached data at once, then refresh it in the background.
Taught in
- Type-Safe Client Generation: Orval & Automated SDKs — Production Full-Stack Engineering
- Optimistic UI Architecture: Cache & Rollback Protocols — Production Full-Stack Engineering
- Client-Side Data Fetching Architectures with Suspense — React 19 & Modern Component Architecture