tanstack-query

Guide TanStack Query v5 data fetching with useSuspenseQuery and mutations.

1|Updated Dec 15, 2025
One-click install
npx skills add https://github.com/mihaamiharu/twe --skill tanstack-query-mihaamiharu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/mihaamiharu/twe/tree/main/.agent/skills/tanstack-query
Command: npx skills add https://github.com/mihaamiharu/twe --skill tanstack-query-mihaamiharu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill streamlines modern data fetching in React applications by providing patterns and best practices for using TanStack Query v5, ensuring efficient, robust, and maintainable data management.

Core Features & Use Cases

  • Efficient Data Fetching: Leverages useSuspenseQuery for seamless integration with React Suspense, eliminating manual loading and error states in components.
  • State Management: Manages server state, cache invalidation, and optimistic updates for mutations.
  • API Integration: Demonstrates patterns for centralized API services and structured query keys.
  • Use Case: When building a dashboard that displays user profiles and their associated posts, use this Skill to efficiently fetch and manage the data, ensuring a smooth user experience with automatic cache updates and optimistic UI changes.

Quick Start

Use the tanstack-query skill to fetch a list of posts using useSuspenseQuery and display them in a component.

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 using TanStack Query v5?

TanStack Query v5 fetches data using the useQuery hook for manual state management or useSuspenseQuery for seamless React Suspense integration, automatically handling loading and error states while caching server data.

What is the best way to manage server state and cache invalidation in React?

Managing server state and cache invalidation requires structuring query keys and utilizing mutation hooks. TanStack Query handles state synchronization automatically, allowing you to invalidate caches and trigger optimistic UI updates after data mutations.

How do I handle loading and error states without manual conditional rendering?

Using useSuspenseQuery for data fetching eliminates manual loading and error state rendering. It integrates directly with React Suspense to automatically suspend component rendering until the API integration completes and data is available.

Can I implement optimistic updates for mutations in React applications?

Yes, optimistic updates are supported during mutations to provide a smooth user experience. You configure the mutation to immediately update the UI while automatically synchronizing server state and managing cache invalidation in the background.

Does TanStack Query v5 work with centralized API services?

TanStack Query v5 works effectively with centralized API services by demonstrating patterns for structured query keys. This approach ensures efficient data retrieval, maintainable state management, and optimized application performance across your components.

When should I use useSuspenseQuery instead of useQuery for data fetching?

Use useSuspenseQuery when you want to leverage React Suspense to declaratively handle loading states, whereas useQuery is suitable when you need manual control over component rendering during API integration and data fetching operations.