tanstack-query

Implements TanStack Query patterns for server state, caching, and route loaders in React.

3|1|Updated Jan 12, 2026
One-click install
npx skills add https://github.com/nghyane/VSTEP --skill tanstack-query-nghyane
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/nghyane/VSTEP/tree/main/apps/_deprecated/frontend-v2/.agents/skills/tanstack-query
Command: npx skills add https://github.com/nghyane/VSTEP --skill tanstack-query-nghyane

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It prevents common React data-fetching mistakes such as fetching inside useEffect, mirroring server state in useState, race conditions, and double-fetching under StrictMode by enforcing TanStack Query conventions. ## Core Features & Use Cases - Query Options Factories: Define queries once with queryOptions and reuse them in both route loaders (ensureQueryData) and components (useSuspenseQuery). - Key Factory Pattern: Centralize query keys per resource ({ all, list(params), detail(id) }) so cache invalidation always goes through the factory. - URL-Driven State: Keep filters, pagination, and sorting in validated search params so query keys derive from the URL. - Use Case: When building a React route that displays a detail page, define the query in a factory, prefetch it in the route loader, and consume it with useSuspenseQuery while Suspense and ErrorBoundary handle loading and error states. ## Quick Start Apply the tanstack-query skill to refactor this component so it fetches data through a queryOptions factory and route loader instead of useEffect.

Frequently Asked Questions about tanstack-query

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

FAQPage Schema
How do I fetch data in React without useEffect?▼

Use TanStack Query with a queryOptions factory instead of useEffect. Define the query once, prefetch it in a route loader with ensureQueryData, and read it in the component with useSuspenseQuery to avoid race conditions and StrictMode double-fetching.

How to structure TanStack Query keys for cache invalidation?▼

Use a key factory per resource exposing all, list(params), and detail(id) as the single source of keys. Mutations invalidate through the factory, for example queryClient.invalidateQueries({ queryKey: keys.list() }), never by setting state manually.

Should I use useState to store server data in React?▼

No, server state belongs to TanStack Query, not useState. Mirroring server data in local state causes stale UI and synchronization bugs; use useSuspenseQuery to read cached server data directly.

How do I handle loading and error states with TanStack Query?▼

Let Suspense and an ErrorBoundary at the route level handle loading and error states when using useSuspenseQuery. Components only handle the empty and success states, keeping rendering logic simple.

Can TanStack Query work with TanStack Router loaders?▼

Yes, route loaders can prefetch data with queryClient.ensureQueryData using the same queryOptions factory the component uses. This guarantees data is cached before the route renders and avoids duplicate fetching.