tanstack-query-best-practices

Codify TanStack Query best practices for data fetching, caching, and SSR hydration in React apps.

Updated Apr 14, 2026
One-click install
npx skills add https://github.com/iEnergyy/opsflow --skill tanstack-query-best-practices-ienergyy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query-best-practices
Source: https://github.com/iEnergyy/opsflow/tree/main/.agents/skills/tanstack-query-best-practices
Command: npx skills add https://github.com/iEnergyy/opsflow --skill tanstack-query-best-practices-ienergyy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TanStack Query best practices guide helps teams implement robust server-state management by standardizing data fetching, caching, mutations, and SSR integration across React applications.

Core Features & Use Cases

  • Guidance on query keys, caching strategies, mutations, and SSR integration.
  • Patterns for data fetching, optimal invalidation, and error handling across React apps.
  • Real-world scenarios showing how to structure queries, cache, and update UI.

Quick Start

Audit your existing TanStack Query usage against the rules in this guide and implement targeted improvements to reduce stale data and improve UI responsiveness.

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 deterministic query keys for TanStack Query caching?

Structure deterministic query keys by codifying best practices for data fetching and caching. This organizes query dependencies into hierarchical arrays, enabling safe SSR hydration and targeted invalidation to reduce network requests and UI inconsistencies.

What is the best way to handle server state synchronization and mutations in React Query?

Handle server state synchronization by applying patterns for mutations and error handling. Enforce targeted invalidation after mutations to update the UI safely, ensuring robust server state synchronization across typical data-driven React apps.

How does TanStack Query SSR hydration work to reduce network requests?

SSR hydration works by enforcing safe server state synchronization patterns. Applying deterministic query keys during SSR hydration prevents UI inconsistencies and reduces redundant network requests when initializing data-driven React apps.

Why does my React Query caching strategy cause stale data and UI inconsistencies?

Caching strategies cause stale data when lacking targeted invalidation and deterministic query keys. Audit existing TanStack Query usage against best practices for data fetching and server state synchronization to fix these UI inconsistencies.

Can I use these TanStack Query patterns for data fetching in any data-driven React app?

You can apply these patterns to typical data-driven React apps. The guidance covers query keys, caching strategies, mutations, and SSR integration, ensuring robust server state management regardless of specific app scale or context.

When do I need targeted invalidation for TanStack Query mutations?

You need targeted invalidation when executing mutations that alter server state. Enforcing deterministic query keys alongside targeted invalidation ensures safe SSR hydration and reduces network requests without causing UI inconsistencies.