tanstack-query-best-practices

Implement TanStack Query patterns for server state management in React applications.

Updated May 11, 2026
One-click install
npx skills add https://github.com/irizqi/agent-skills --skill tanstack-query-best-practices-irizqi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query-best-practices
Source: https://github.com/irizqi/agent-skills/tree/main/skills/tanstack-query
Command: npx skills add https://github.com/irizqi/agent-skills --skill tanstack-query-best-practices-irizqi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the complexity of managing server state in React applications, preventing common pitfalls like cache inconsistencies, unnecessary network requests, and poor user experiences during data mutations.

Core Features & Use Cases

  • Cache Optimization: Provides expert-level guidance on configuring staleTime, gcTime, and invalidation strategies to ensure data freshness and performance.
  • Mutation Patterns: Offers robust templates for optimistic updates, error handling, and cross-component mutation tracking.
  • Use Case: When building a complex dashboard, use these patterns to implement efficient parallel data fetching, handle offline synchronization, and ensure UI components remain perfectly in sync with server data.

Quick Start

Apply the tanstack-query-best-practices skill to audit my current query configuration and suggest improvements for cache invalidation and staleTime settings.

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 optimize TanStack Query cache invalidation and staleTime settings in React?

Optimize TanStack Query cache invalidation by auditing staleTime and gcTime configurations to ensure data freshness, applying targeted invalidation strategies that prevent unnecessary network requests and maintain cache consistency across complex React component trees.

What is the best way to handle optimistic updates and mutations with TanStack Query?

Handle optimistic updates with TanStack Query by implementing robust mutation patterns for cross-component tracking and error handling, ensuring UI components remain perfectly in sync with server data during data mutations and offline synchronization.

How does TanStack Query manage server state differently from standard React state management?

TanStack Query manages server state by separating it from local client state, providing built-in mechanisms for data fetching, caching, and synchronization to prevent cache inconsistencies and poor user experiences common in standard React state management.

Can I use TanStack Query for SSR hydration and parallel data fetching in complex dashboards?

Yes, you can use TanStack Query for SSR hydration and parallel data fetching in complex dashboards, applying advanced patterns to optimize data fetching, ensure responsive interfaces, and handle offline synchronization effectively.

Why does my React application make unnecessary network requests when using TanStack Query?

Unnecessary network requests in TanStack Query often occur due to suboptimal staleTime configurations and poor invalidation strategies, requiring an audit of query configurations to balance data freshness with caching performance.