Skip to main content
rule CX Codex

client-swr-dedup — Claude Code rule: SWR and installation

The client-swr-dedup rule recommends SWR to share requests between component instances and reuse cached data. It fits React projects that fetch data on the client.

MIT ★ 7,191 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/client-swr-dedup.md
Open on GitHub

What client-swr-dedup does

The rule recommends replacing a component’s standalone fetch call inside useEffect with useSWR. When several instances request the same resource, SWR deduplicates those requests; it also provides caching and revalidation.

For immutable content, the example imports useImmutableSWR from @/lib/swr. For updates, it uses useSWRMutation from swr/mutation and triggers the mutation from a button. The immutable-data example depends on that project-specific @/lib/swr import.

In Claude Code, place the rule at .claude/rules/client-swr-dedup.md. Its examples cover client-side data fetching with SWR, not server request setup.

What it helps with

  • stop component instances from issuing duplicate requests
  • reuse cached data fetched with SWR
  • revalidate data after loading
  • fetch static configuration with useImmutableSWR
  • trigger a user update with useSWRMutation

Example prompts for the agent

  • Refactor the user list to use SWR so component instances share a request.
  • Fetch /api/config with useImmutableSWR from @/lib/swr.
  • Add a user update using useSWRMutation from swr/mutation.

How to install client-swr-dedup

Manually: put the files in place

.claude/rules/client-swr-dedup.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about client-swr-dedup

How do I install client-swr-dedup in Claude Code?

Add the rule file at .claude/rules/client-swr-dedup.md.

What does client-swr-dedup do?

It recommends SWR to deduplicate requests across component instances, cache fetched data, and revalidate it.

How does the rule handle immutable data?

Its example uses useImmutableSWR imported from @/lib/swr.

Source text

client-swr-dedup.md · MIT
---
title: Use SWR for Automatic Deduplication
impact: MEDIUM-HIGH
impactDescription: automatic deduplication
tags: client, swr, deduplication, data-fetching
---

## Use SWR for Automatic Deduplication

SWR enables request deduplication, caching, and revalidation across component instances.

**Incorrect (no deduplication, each instance fetches):**

```tsx
function UserList() {
  const [users, setUsers] = useState([])
  useEffect(() => {
    fetch('/api/users')
      .then(r => r.json())
      .then(setUsers)
  }, [])
}
```

**Correct (multiple instances share one request):**

```tsx
import useSWR from 'swr'

function UserList() {
  const { data: users } = useSWR('/api/users', fetcher)
}
```

**For immutable data:**

```tsx
import { useImmutableSWR } from '@/lib/swr'

function StaticContent() {
  const { data } = useImmutableSWR('/api/config', fetcher)
}
```

**For mutations:**

```tsx
import { useSWRMutation } from 'swr/mutation'

function UpdateButton() {
  const { trigger } = useSWRMutation('/api/user', updateUser)
  return <button onClick={() => trigger()}>Update</button>
}
```

Reference: [https://swr.vercel.app](https://swr.vercel.app)

© tech-leads-club · MIT · tech-leads-club/agent-skills

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set130

The whole set →
async-api-routes async-api-routes prevents sequential waterfall requests in API routes and Server Actions. It instructs the assistant to launch independent promises immediately rather than chaining awaits. CX Codex +1 ★ 7,191repo stars js-early-exit The js-early-exit rule recommends returning as soon as a function’s result is clear. It fits checks where continuing after the first error serves no purpose. CX Codex +1 ★ 7,191repo stars rerender-memo rerender-memo — a rule that guides your agent to extract expensive computations into memoized components, enabling early returns without triggering child logic. Speeds up React re-render paths. CX Codex +1 ★ 7,191repo stars bundle-preload bundle-preload directs the agent to preload heavy JavaScript chunks on user intent like hover or focus. This cuts perceived interface latency. CX Codex +1 ★ 7,191repo stars rerender-memo-with-default-value rerender-memo-with-default-value — a rule that prevents memoization from breaking when React components have default values (functions, objects, arrays) in parameters. It instructs you to extract these defaults into module-level constants. CX Codex +1 ★ 7,191repo stars rendering-animate-svg-wrapper rendering-animate-svg-wrapper enforces wrapping svg elements in an outer div container for CSS animations. Enables GPU hardware acceleration across browsers. CX Codex +1 ★ 7,191repo stars rerender-derived-state-no-effect The rerender-derived-state-no-effect rule keeps derived values out of React state and avoids effects that mirror props. Use it when reviewing components for extra renders and state drift. CX Codex +1 ★ 7,191repo stars rerender-move-effect-to-event rerender-move-effect-to-event tells the agent to fire a side effect from the handler that caused it, not from useEffect watching a state flag. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open