tanstack-query-best-practices

Standardize TanStack Query usage in React apps with structured rules for caching and invalidation.

Updated Mar 10, 2026
One-click install
npx skills add https://github.com/mohamed-g-shoaib/rootly --skill tanstack-query-best-practices-mohamed-g-shoaib
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query-best-practices
Source: https://github.com/mohamed-g-shoaib/rootly/tree/main/.agents/skills/tanstack-query-best-practices
Command: npx skills add https://github.com/mohamed-g-shoaib/rootly --skill tanstack-query-best-practices-mohamed-g-shoaib

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TanStack Query best practices address inconsistent data-fetching patterns and cache invalidation across React applications, reducing bugs and improving performance.

Core Features & Use Cases

  • Comprehensive rule-based patterns for query keys, caching, invalidation, mutations, SSR integration, and performance optimization.
  • Guidance for common scenarios: data fetching, mutations, prefetching, SSR, and offline support, plus patterns for error handling and parallel queries.
  • Templates and examples to standardize how queries are authored and invalidated in production apps.

Quick Start

Review this guide and refactor your React app to adopt consistent TanStack Query keys, caching, invalidation, and SSR patterns.

Frequently Asked Questions about tanstack-query-best-practices

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

FAQPage Schema
What's the best way to structure TanStack Query keys to prevent cache bugs?

TanStack Query keys should follow a structured, hierarchical rule set to prevent cache bugs. Standardizing query keys as arrays ensures consistent data fetching, accurate cache invalidation, and predictable server-state management across your React app.

How do I standardize cache invalidation and mutations in React Query?

Standardize cache invalidation and mutations in React Query by applying uniform patterns and templates. This approach ensures that data inconsistencies are prevented during mutations by systematically invalidating affected query keys.

Does this guide cover TanStack Query SSR and SSG integration patterns?

Yes, this covers TanStack Query SSR and SSG integration patterns. It provides comprehensive, rule-based guidance for integrating server-side rendering and static generation to ensure consistent data fetching and hydration in React applications.

Why does inconsistent TanStack Query caching cause data inconsistencies?

Inconsistent TanStack Query caching causes data inconsistencies because fragmented data-fetching patterns lead to mismatched server-state and stale caches. Applying a structured rule set for caching and invalidation resolves these bugs and improves application performance.

Can I refactor existing data-fetching logic to follow these TanStack Query best practices?

Yes, you can refactor existing data-fetching logic to follow TanStack Query best practices. The guide provides templates and examples to standardize how queries are authored, configured, and invalidated in production React apps.

How do I handle parallel queries and prefetching with TanStack Query?

Handle parallel queries and prefetching with TanStack Query by utilizing the provided structured patterns. These templates guide implementation for common scenarios like data fetching, prefetching, and error handling to optimize React app performance.