tanstack-query-best-practices

Codify TanStack Query best practices for React data fetching and caching.

1|Updated Feb 7, 2026
One-click install
npx skills add https://github.com/aarsh21/better-issues --skill tanstack-query-best-practices-aarsh21
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query-best-practices
Source: https://github.com/aarsh21/better-issues/tree/main/.agents/skills/tanstack-query-best-practices
Command: npx skills add https://github.com/aarsh21/better-issues --skill tanstack-query-best-practices-aarsh21

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a comprehensive set of rules and guidelines to ensure TanStack Query (React Query) is implemented effectively, preventing common pitfalls and optimizing data fetching, caching, and state management in React applications.

Core Features & Use Cases

  • Optimized Data Fetching: Implement best practices for query keys, caching, and refetching to minimize network requests and improve performance.
  • Robust State Management: Ensure data integrity and consistency through proper mutation handling, error management, and optimistic updates.
  • Advanced Patterns: Leverage techniques like prefetching, infinite queries, and SSR integration for a seamless user experience.
  • Use Case: When building a dashboard that displays real-time data, user profiles, and lists of items, applying these best practices ensures the data loads quickly, stays fresh, and updates responsively without overwhelming the server or causing UI glitches.

Quick Start

Activate the tanstack-query-best-practices skill to review the rules for optimizing data fetching and caching in your React application.

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 for caching in React?

Optimizing data fetching in TanStack Query requires adhering to specific rules for query key structure, caching strategies, and refetching configurations. This minimizes network requests, ensures data integrity, and improves overall React application performance.

How do I handle mutation rollback and error management with React Query?

Robust state management in TanStack Query is achieved by applying specific rules for mutation rollback, error boundary usage, and error management. This guarantees data consistency during optimistic updates and reliable server state synchronization.

Does TanStack Query support SSR integration and infinite scrolling?

Yes, TanStack Query supports SSR integration and infinite scrolling through advanced patterns. Leveraging these techniques ensures seamless data fetching, efficient caching, and robust performance optimization within React applications.

When do I need to use prefetching in TanStack Query?

Prefetching in TanStack Query is needed when you want to load data before it is required by the UI, ensuring fast load times and a seamless user experience. It is an advanced pattern that minimizes waiting periods for real-time dashboard data.