mcpField
R
react-fetch-cache-patterns

react-fetch-cache-patterns

github.com/pproencaDevelopment218170 installsUpdated 11w ago
Repository

About react-fetch-cache-patterns

A skill with React data-fetching and caching patterns for applications handling many API requests. It serves developers optimizing request flow, backend load, and failure handling, with examples for both query libraries and library-free React.

Key features

  1. 0148 rules across eight categories
  2. 02Request batching and deduplication
  3. 03Cache strategy and invalidation
  4. 04Backend concurrency and retry controls
  5. 05Prefetch and failure-resilience patterns
  6. 06Ready-to-adapt code templates

Use cases

  1. 01Reducing waterfalls in React data loading
  2. 02Limiting backend load from feeds or lists
  3. 03Adding caching, prefetch, or retry behavior
  4. 04Reviewing fetch code for resilience

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pproenca/dot-skills --skill react-fetch-cache-patterns

After installing, type/react-fetch-cache-patternsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
metadata.json
assets/templates/
_template.md
carousel-data-loader.template.tsx
infinite-feed.template.tsx
prefetch-link.template.tsx
request-collapser.template.ts
use-resource-query-no-deps.template.tsx
use-resource-query.template.tsx
references/
_sections.md
cache-deterministic-keys.md
cache-normalize-shared-entities.md
cache-select-subscribed-fields.md
cache-set-stale-time.md
cache-shared-key-factory.md
cache-stale-while-revalidate.md
cache-tiered-stale-fresh.md
feed-bounded-working-set.md
feed-cursor-pagination.md
feed-image-lazy-and-sized.md
feed-multi-carousel-isolation.md
feed-split-summary-from-detail.md
feed-stable-keys-across-pages.md
feed-virtualize-long-lists.md
mutate-cancel-queries-on-mutate.md
mutate-optimistic-updates-with-rollback.md
mutate-set-data-over-invalidate.md
mutate-surgical-invalidation.md
orch-avoid-effect-chains.md
orch-batch-n-plus-one-fanout.md

Details

From the project README

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

#CategoryImpactPrefixRules
1Request OrchestrationCRITICALorch-7
2Cache StrategyCRITICALcache-7
3Backend ProtectionCRITICALprotect-7
4Prefetch & HydrationHIGHprefetch-6
5Failure ResilienceHIGHresilience-6
6Feed & Carousel PatternsMEDIUM-HIGHfeed-7
7Mutation & InvalidationMEDIUMmutate-4
8Component PatternsMEDIUMrender-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/:

TemplateLibrary depsPurpose
use-resource-query.template.tsxTanStack QueryStandard query hook with key factory, retry, abort, optional suspense
use-resource-query-no-deps.template.tsxNone (pure React + AbortController)Same patterns as above, library-free: hand-rolled cache, dedup, retry with jitter, staleTime/gcTime, concurrency limit
carousel-data-loader.template.tsxTanStack Query + react-error-boundarySingle carousel (summary + viewport-triggered detail) and multi-carousel feed with per-carousel failure isolation
infinite-feed.template.tsxTanStack Query + TanStack VirtualCursor-paginated infinite feed with virtualization and bounded working set
prefetch-link.template.tsxNoneHover/intent prefetch link wrapper
request-collapser.template.tsNoneIn-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

FileDescription
references/_sections.mdCategory definitions, ordering, impact rationale
assets/templates/_template.mdTemplate for authoring new rules
metadata.jsonVersion, 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)

Comments

Markdown supported