Agent Skills: Experimental React Data Fetching & Caching Best Practices

React data-fetching patterns at scale — recommender carousels, infinite feeds, pages with many parallel fetches, dashboards. Covers request orchestration (parallelism, batching, deduplication), cache strategy (keys, normalization, staleTime, SWR), backend protection (concurrency caps, debounce/throttle, jittered retries, circuit breakers), prefetching (route loaders, hover/intent, idle, server hydration), failure resilience (AbortController, timeouts, error boundaries, stale fallback, idempotent mutations), and feed/carousel patterns (virtualization, cursor pagination, summary/detail split). Includes 5 ready-to-use scaffolding templates (resource query hook, carousel data loader, infinite feed, hover-prefetch link, request collapser). Trigger when building, reviewing, or refactoring React components that fetch data — even if the user doesn't explicitly mention "performance" or "scale".

UncategorizedID: pproenca/dot-skills/react-fetch-cache-patterns

Install this agent skill to your local

pnpm dlx add-skill https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/react-fetch-cache-patterns

Skill Files

Browse the full folder contents for react-fetch-cache-patterns.

Download Skill

Loading file tree…

skills/.experimental/react-fetch-cache-patterns/SKILL.md

Skill Metadata

Name
react-fetch-cache-patterns
Description
React data-fetching patterns at scale — recommender carousels, infinite feeds, pages with many parallel fetches, dashboards. Covers request orchestration (parallelism, batching, deduplication), cache strategy (keys, normalization, staleTime, SWR), backend protection (concurrency caps, debounce/throttle, jittered retries, circuit breakers), prefetching (route loaders, hover/intent, idle, server hydration), failure resilience (AbortController, timeouts, error boundaries, stale fallback, idempotent mutations), and feed/carousel patterns (virtualization, cursor pagination, summary/detail split). Includes 5 ready-to-use scaffolding templates (resource query hook, carousel data loader, infinite feed, hover-prefetch link, request collapser). Trigger when building, reviewing, or refactoring React components that fetch data — even if the user doesn't explicitly mention "performance" or "scale".

Experimental React Data Fetching & Caching Best Practices

Implementation patterns for React applications that fetch and cache many API requests without overwhelming the backend. 48 rules across 8 categories, ordered by execution lifecycle impact — earlier categories cascade through everything downstream. Templates show both library-based (TanStack Query, SWR) and library-free (pure React + AbortController) implementations so the patterns are usable regardless of stack constraints.

When to Apply

  • Writing or reviewing a React component that calls fetch, useQuery, useSWR, or any data-fetching hook
  • Designing a list, feed, or carousel that displays many items each requiring data
  • Investigating "the backend is getting hammered" or "the page loads slowly" symptoms
  • Choosing between client-side fetching, route loaders, server components, or SSR
  • Implementing prefetch, retry, optimistic updates, or any failure-handling logic
  • Refactoring code that already does data fetching but with waterfalls, no cache strategy, or no concurrency limits

Rule Categories by Priority

| # | Category | Impact | Prefix | Rules | |---|----------|--------|--------|-------| | 1 | Request Orchestration | CRITICAL | orch- | 7 | | 2 | Cache Strategy | CRITICAL | cache- | 7 | | 3 | Backend Protection | CRITICAL | protect- | 7 | | 4 | Prefetch & Hydration | HIGH | prefetch- | 6 | | 5 | Failure Resilience | HIGH | resilience- | 6 | | 6 | Feed & Carousel Patterns | MEDIUM-HIGH | feed- | 7 | | 7 | Mutation & Invalidation | MEDIUM | mutate- | 4 | | 8 | Component Patterns | MEDIUM | render- | 4 |

Quick Reference

1. Request Orchestration (CRITICAL)

2. Cache Strategy (CRITICAL)

3. Backend Protection (CRITICAL)

4. Prefetch & Hydration (HIGH)

5. Failure Resilience (HIGH)

6. Feed & Carousel Patterns (MEDIUM-HIGH)

7. Mutation & Invalidation (MEDIUM)

8. Component Patterns (MEDIUM)

How to Use

  1. Open references/_sections.md for category definitions and impact rationale
  2. Read individual rule files for incorrect-vs-correct code examples
  3. For ready-to-use scaffolds, see scaffolding templates
  4. The AGENTS.md navigation document (auto-generated) provides a TOC for browsing

Scaffolding Templates

Six ready-to-adapt code templates under assets/templates/:

| Template | Library deps | Purpose | |----------|-------------|---------| | use-resource-query.template.tsx | TanStack Query | Standard query hook with key factory, retry, abort, optional suspense | | use-resource-query-no-deps.template.tsx | None (pure React + AbortController) | Same patterns as above, library-free: hand-rolled cache, dedup, retry with jitter, staleTime/gcTime, concurrency limit | | carousel-data-loader.template.tsx | TanStack Query + react-error-boundary | Single carousel (summary + viewport-triggered detail) and multi-carousel feed with per-carousel failure isolation | | infinite-feed.template.tsx | TanStack Query + TanStack Virtual | Cursor-paginated infinite feed with virtualization and bounded working set | | prefetch-link.template.tsx | None | Hover/intent prefetch link wrapper | | request-collapser.template.ts | None | In-flight deduplication + concurrency limit utility |

Library-free path: if you can't add TanStack Query / SWR / DataLoader to your bundle (size constraints, host-app conflicts, dependency bans), start with use-resource-query-no-deps.template.tsx — it implements the core cache/dedup/retry/abort patterns in ~250 lines using only React and the web platform. The other templates that depend on TanStack can be adapted on top of it; only the request-collapser and prefetch-link templates are zero-dep out of the box.

Reference Files

| File | Description | |------|-------------| | references/_sections.md | Category definitions, ordering, impact rationale | | assets/templates/_template.md | Template for authoring new rules | | metadata.json | Version, references, abstract |

Related Skills

  • react-optimise — General React render performance (this skill is data-fetching-specific)
  • nextjs-bundle-optimizer — Bundle/payload optimization for Next.js
  • inngest-nextjs-patterns — Server-side workflow patterns (complements server-fetch guidance)