tanstack-query

Manage asynchronous server-state fetching, caching, and synchronization in React applications.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Hollowvyn/cognipace-v2 --skill tanstack-query-hollowvyn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/Hollowvyn/cognipace-v2/tree/main/.agents/skills/tanstack-query
Command: npx skills add https://github.com/Hollowvyn/cognipace-v2 --skill tanstack-query-hollowvyn

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TanStack Query solves the pain of manual, error-prone server data fetching by providing a consistent way to cache, refetch, and keep UI synchronized with remote data.

Core Features & Use Cases

  • Server-state caching and stale-while-revalidate: Reuse previously fetched data instantly while refetching in the background to keep views up to date.
  • Queries and mutations with lifecycle states: Manage loading/error/success states for both reads and writes, including retries and cancellation.
  • Cache orchestration for real apps: Coordinate invalidation, optimistic updates, and pagination/infinite loading patterns for responsive UX.

Example use case: when a user edits a record, update the UI immediately with an optimistic mutation, then invalidate the relevant query keys to ensure the final cached data matches the server.

Quick Start

Use the tanstack-query skill to fetch and cache the current user profile for a given userId in a React component using a queryKey and queryFn.

Frequently Asked Questions about tanstack-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cache server-state in React and keep the UI synchronized?

To cache server-state in React, you fetch remote data using query hooks with stable query keys and query functions. The cache applies a stale-while-revalidate strategy, instantly reusing fetched data while refetching in the background to keep views updated.

How do I handle optimistic updates and cache invalidation after a mutation?

Optimistic updates and cache invalidation are handled by using mutation hooks to immediately update the UI with predicted data, then invalidating relevant query keys after the server responds to ensure the final cached data matches the remote state.

What is the best way to manage data-fetching for paginated or infinite scrolling UIs?

The best way to manage data-fetching for paginated or infinite scrolling UIs is orchestrating cache requests through dedicated pagination and infinite loading query patterns, which coordinate background refetching and data synchronization for responsive UX.

Does TanStack Query work with GraphQL and tRPC data retrieval?

TanStack Query works with GraphQL and tRPC data retrieval by managing asynchronous server-state fetching across any REST, GraphQL, or tRPC endpoint, handling retries, cancellation, and lifecycle states for both reads and writes.

Why do I need stable query keys for server-state caching?

Stable query keys are required for server-state caching because they uniquely identify and store fetched data, enabling the cache to reuse previously fetched data instantly, coordinate background refetching, and accurately target cache invalidation after mutations.

When should I not use manual data-fetching instead of a server-state cache?

You should not use manual data-fetching when your application requires background refetching, dependent or parallel request orchestration, or optimistic updates, as managing these lifecycle states manually is error-prone without a dedicated server-state cache.