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
.claude/rules/client-swr-dedup.mdWhat 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/configwithuseImmutableSWRfrom@/lib/swr. - Add a user update using
useSWRMutationfromswr/mutation.
How to install client-swr-dedup
Manually: put the files in place
.claude/rules/client-swr-dedup.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/client-swr-dedup.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/client-swr-dedup.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/client-swr-dedup.mdManually: put the files in place
.clinerules/client-swr-dedup.mdStep 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