tanstack-query-best-practices

Standardize TanStack Query server-state management for React apps.

1|Updated Apr 18, 2026
One-click install
npx skills add https://github.com/tkgstrator/KotoTV --skill tanstack-query-best-practices-tkgstrator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query-best-practices
Source: https://github.com/tkgstrator/KotoTV/tree/main/.claude/skills/tanstack-query-best-practices
Command: npx skills add https://github.com/tkgstrator/KotoTV --skill tanstack-query-best-practices-tkgstrator

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TanStack Query conventions for organizing server state management in client apps to ensure consistent query keys, data freshness, and mutation invalidation patterns across the codebase.

Core Features & Use Cases

  • Standardized query keys and stable invalidation patterns to keep UI in sync across screens (channels, programs, recordings) and reduce data staleness.
  • Centralized QueryClient lifecycle with sane default options and predictable retry/freshness behavior.
  • Colocated hooks in the designated directory to promote reuse and cohesive data access patterns, with examples like useChannels, usePrograms, useRecordings, etc.
  • Clear error handling and route integration guidance to enable prefetching and reuse of cached data where appropriate.
  • Guidance on stale time strategies and modularized cache boundaries to balance performance and freshness.

Quick Start

Initialize a single QueryClient and colocate data hooks under packages/client/src/hooks/ following the stable key conventions and invalidation patterns.

Frequently Asked Questions about tanstack-query-best-practices

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

FAQPage Schema
How do I structure TanStack Query keys for consistent cache management in React?

TanStack Query cache management relies on stable query keys using typed tuples to ensure predictable data fetching and mutation invalidation. Structuring keys hierarchically allows precise cache invalidation across routes like channels and programs while maintaining UI sync.

What is the best way to organize TanStack Query hooks in a React project?

The best way to organize TanStack Query hooks is colocating them in a designated directory like packages/client/src/hooks/. This promotes reusable data access patterns with cohesive examples like useChannels and useRecordings, ensuring consistent server-state management across the application.

How do I handle mutation invalidation with React Query to keep UI data fresh?

Mutation invalidation in React Query requires stable query keys tied to your data boundaries. By invalidating specific query keys after mutations, cached data refreshes automatically, keeping UI in sync across screens and reducing data staleness without manual refetching.

How do I configure a single QueryClient lifecycle for a React app?

Configuring a single QueryClient lifecycle involves initializing one client instance with centralized default options. This predicts retry behavior and freshness across the app, ensuring consistent server-state management and avoiding duplicate cache boundaries in client applications.

What stale time strategy should I use for TanStack Query cache boundaries?

Stale time strategies in TanStack Query should balance performance and freshness by modularizing cache boundaries. Configuring appropriate stale times per query type reduces unnecessary refetching while ensuring data remains current for routes like channels, programs, and recordings.

Does TanStack Query work with route-level prefetching and cached data reuse?

TanStack Query supports route integration with prefetching and cached data reuse. By leveraging clear error handling and stable query keys, cached data transfers seamlessly between routes, improving performance while maintaining predictable freshness behavior across the React application.