tanstack-query-best-practices

Implement TanStack Query best practices for data fetching, caching, and mutations in React.

Updated Nov 18, 2024
One-click install
npx skills add https://github.com/Tomytool/citaciones --skill tanstack-query-best-practices-tomytool
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query-best-practices
Source: https://github.com/Tomytool/citaciones/tree/main/.agents/skills/tanstack-query-best-practices
Command: npx skills add https://github.com/Tomytool/citaciones --skill tanstack-query-best-practices-tomytool

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a comprehensive set of best practices to optimize data fetching, caching, mutations, and server state management in React applications using TanStack Query (React Query).

Core Features & Use Cases

  • Optimized Data Fetching: Learn to implement efficient query keys, caching strategies, and prefetching.
  • Robust Mutations: Master mutation patterns for data integrity and responsive UI updates.
  • Error Handling & Performance: Implement best practices for error boundaries, performance tuning, and offline support.
  • Use Case: When building a complex dashboard with multiple data sources, this Skill ensures your data is fetched efficiently, cached effectively, and updates seamlessly, providing a smooth user experience.

Quick Start

Review the rules for optimizing query keys and caching strategies to improve application performance.

Frequently Asked Questions about tanstack-query-best-practices

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

FAQPage Schema
How do I organize TanStack Query keys for efficient data fetching and caching?

Implement robust mutation patterns in TanStack Query by utilizing mutation callbacks to update the local cache directly. This approach maintains data integrity and provides responsive UI updates without requiring full refetches.

What is the best way to handle errors when fetching data with React Query?

Handle errors in React Query by integrating error boundaries with query configurations. Implementing centralized error handling within your mutation and query patterns ensures data fetching failures are caught and managed gracefully.

How do I prefetch data with TanStack Query to improve React application performance?

Prefetch data with TanStack Query by triggering queries before navigation or user interaction. This caching strategy loads necessary server state in the background, ensuring immediate UI rendering and smoother performance.

Does TanStack Query work with SSR in React applications?

TanStack Query works with SSR in React applications by supporting server state hydration. Integrating SSR prefetching strategies ensures your cached data is initialized correctly on the server and seamlessly transferred to the client.

When do I need offline support in a React Query data fetching setup?

You need offline support in a React Query setup when your application must maintain functionality without a network. Implementing offline caching strategies and persistent storage ensures mutations and data fetching resume smoothly upon reconnection.