swr

Guide correct SWR v2 implementation for React and Next.js data fetching.

1|Updated May 12, 2026
One-click install
npx skills add https://github.com/Firzus/agent-skills --skill swr-firzus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swr
Source: https://github.com/Firzus/agent-skills/tree/main/skills/web/swr
Command: npx skills add https://github.com/Firzus/agent-skills --skill swr-firzus

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you implement SWR data fetching correctly in React and Next.js so cached data, revalidation, and mutations behave predictably instead of causing stale UI, duplicate requests, or cache mismatches.

Core Features & Use Cases

  • Cache Identity and Key Design: Define stable keys that include every input affecting the response, such as filters, auth scope, locale, or tenant.
  • Fetching and Revalidation: Set up useSWR, shared fetchers, loading states, error handling, retry behavior, and global SWRConfig defaults.
  • Mutations and Optimistic UI: Update or invalidate cache entries safely after writes, including rollback behavior and cross-component refresh.
  • Pagination, Subscriptions, and Next.js: Handle infinite lists, realtime subscriptions, and App Router client/server hydration boundaries.
  • Use Case: A dashboard with user-specific lists, live updates, and paginated search results can keep data fresh without breaking cache consistency.

Quick Start

Ask for help implementing or reviewing your SWR hooks, cache keys, mutations, and Next.js hydration boundaries in the current codebase.

Frequently Asked Questions about swr

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

FAQPage Schema
How do I prevent stale UI and duplicate requests when fetching data in React?

Preventing stale UI and duplicate requests in React requires stable SWR cache keys that include filters, auth scope, and locale, ensuring shared fetchers manage cache identity and predictable revalidation across components.

What is the best way to structure SWR cache keys for user-specific dashboard lists?

The best way to structure SWR cache keys for dashboard lists is defining stable keys that include every input affecting the response, such as filters, auth scope, locale, or tenant, to keep cached data predictable and prevent mismatches.

How do I implement optimistic UI updates and cache invalidation after mutations in SWR?

Implementing optimistic UI and cache invalidation in SWR involves safely updating cache entries after mutations, applying rollback behavior for failed writes, and triggering cross-component refresh to maintain cache consistency.

Does SWR v2 work with Next.js App Router client component hydration boundaries?

SWR v2 works with Next.js App Router by defining client component boundaries correctly to handle server-hydrated views, ensuring cache behavior remains predictable during client-side data fetching and realtime subscriptions.

Why does my SWR cache return mismatched data when applying active filters?

SWR cache returns mismatched data when cache keys lack the specific filter inputs affecting the response, requiring stable keys that encapsulate every variable like auth scope, locale, and tenant to maintain correct cache identity.

Can I handle realtime subscriptions and paginated search results using SWR?

Realtime subscriptions and paginated search results are handled in SWR by setting up infinite lists for pagination and managing live updates, keeping data fresh without breaking cache consistency across filtered views.