fetching-rules

Implement end-to-end data fetching in React/Next.js with TanStack Query v5.

3|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/mauriciodelrio/delriodev-skills --skill fetching-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fetching-rules
Source: https://github.com/mauriciodelrio/delriodev-skills/tree/main/es-skills/software/frontend/fetching-rules
Command: npx skills add https://github.com/mauriciodelrio/delriodev-skills --skill fetching-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps orchestrate frontend data fetching in React/Next.js apps by integrating Server Component fetch, TanStack Query, and caching/invalidation.

Core Features & Use Cases

  • Server Component fetch for initial render with SEO considerations
  • TanStack Query for client-side data fetching, caching, and mutations
  • useInfiniteQuery for infinite scrolling with IntersectionObserver
  • Prefetching and hydration across server/client boundaries to reduce perceived latency
  • Consistent loading and error states, with a centralized API client layer for auth and error handling

Quick Start

Run the sample project to implement server and client data fetching with TanStack Query in a React/Next.js app.

Frequently Asked Questions about fetching-rules

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

FAQPage Schema
How do I fetch data in Next.js Server Components and hydrate it with TanStack Query on the client?

To fetch data across server and client boundaries in Next.js, you use Server Component fetch for initial render and TanStack Query for hydration. This approach prefetches data on the server to improve SEO and LCP, then seamlessly hydrates interactive queries client-side.

What's the best way to set up infinite scroll with TanStack Query v5 in a React application?

Infinite scroll in TanStack Query v5 is handled using the useInfiniteQuery hook combined with an IntersectionObserver. This setup prefetches subsequent pages as the user scrolls, reducing perceived latency and maintaining smooth loading states across the application.

How do I manage query keys and cache invalidation for React mutations with TanStack Query?

Managing cache invalidation requires structuring query keys using query-key factories and applying optimistic updates during mutations. This pattern ensures consistent data fetching, automatically synchronizes modified client state, and normalizes API errors through a centralized client layer.

Can I use Server Component fetch and TanStack Query together for initial data loading in Next.js?

Server Component fetch and TanStack Query work together for initial data loading by prefetching on the server and hydrating on the client. This unified strategy ensures SEO requirements are met while retaining interactive client-side caching and mutation capabilities.

How do I handle loading and error states consistently across server and client data fetching?

Consistent loading and error states are managed through a centralized API client that handles authentication and error normalization. This layer enforces concrete workflows for data fetching, ensuring uniform state handling across both server and client boundaries.

Why does my TanStack Query data not hydrate correctly when fetched in Next.js Server Components?

Hydration issues occur when server-fetched data is not properly prefetched or passed to the TanStack Query client. Utilizing a structured workflow with query-key factories and explicit hydration boundaries ensures the server state matches the client cache during initial render.