Tanstack query best practices

From wordbricks/onequery · View interactive version

Tanstack query best practices is an AI agent skill from the GitHub repository wordbricks/onequery. TanStack Query (React Query) best practices for data fetching, caching, mutations, and server state management. Activate when building data-driven React applications with server state.

How to use this skill

Skill file

TanStack Query Best Practices

Comprehensive guidelines for implementing TanStack Query (React Query) patterns in React applications. These rules optimize data fetching, caching, mutations, and server state synchronization.

When to Apply

Rule Categories by Priority

| Priority | Category | Rules | Impact |

|----------|----------|-------|--------|

| CRITICAL | Query Keys | 5 rules | Prevents cache bugs and data inconsistencies |

| CRITICAL | Caching | 5 rules | Optimizes performance and data freshness |

| HIGH | Mutations | 6 rules | Ensures data integrity and UI consistency |

| HIGH | Error Handling | 3 rules | Prevents poor user experiences |

| MEDIUM | Prefetching | 4 rules | Improves perceived performance |

| MEDIUM | Parallel Queries | 2 rules | Enables dynamic parallel fetching |

| MEDIUM | Infinite Queries | 3 rules | Prevents pagination bugs |

| MEDIUM | SSR Integration | 4 rules | Enables proper hydration |

| LOW | Performance | 4 rules | Reduces unnecessary re-renders |

| LOW | Offline Support | 2 rules | Enables offline-first patterns |

Quick Reference

Query Keys (Prefix: `qk-`)

Caching (Prefix: `cache-`)

Mutations (Prefix: `mut-`)

Error Handling (Prefix: `err-`)

Prefetching (Prefix: `pf-`)

Infinite Queries (Prefix: `inf-`)

SSR Integration (Prefix: `ssr-`)

Parallel Queries (Prefix: `parallel-`)

Performance (Prefix: `perf-`)

Offline Support (Prefix: `offline-`)

How to Use

Each rule file in the rules/ directory contains:

  1. Explanation — Why this pattern matters
  2. Bad Example — Anti-pattern to avoid
  3. Good Example — Recommended implementation
  4. Context — When to apply or skip this rule

Full Reference

See individual rule files in rules/ directory for detailed guidance and code examples.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.