swr

swr is a cursor rule for Cursor from nedcodes-ok/cursorrules-collection. It costs 704 tokens per session, scanned A, original, MIT.

A set of coding rules for SWR, a JavaScript library that loads and caches data in web applications. It covers fetching, refreshing, and changing cached data.

In plain words
What is it for?
Use it when building or reviewing React code that gets data from APIs with SWR. It guides request keys, caching, polling, conditional fetching, and updates.
Why use it?
It helps keep data requests consistent and avoids common problems such as duplicate requests, unclear loading states, and stale results.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc). Also seen: mentions Cursor.

Good fit Use it when building or reviewing React code that gets data from APIs with SWR. It guides request keys, caching, polling, conditional fetching, and updates.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/nedcodes-ok/cursorrules-collection/swr
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swr

README.md
[![agentmods](https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/swr/github.svg)](https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/swr)
Your own site
<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/swr"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/swr/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for swr

Your own site · 80×15
<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/swr"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/swr.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 704 This file is loaded in full into every session.
When invoked 704 The same file — it is already loaded in full.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00704 $0.00704
Opus 5.5 $0.00282 $0.00282
Sonnet 5.5 $0.00141 $0.00141
Haiku 4.5 $0.00070 $0.00070

Measured 3mo ago against content hash 79a045463ba9, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

swr scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- Always define a typed fetcher: const fetcher = (url: string) => fetch(url).then(r => r.json()) as Promise<T>
rules-mdc/frameworks/swr.mdc · 54 lines

How it starts

The opening of the file, as written. The whole thing — 54 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SWR Cursor Rules

You are an expert in SWR (stale-while-revalidate). Follow these rules:

Basic Usage

  • Always define a typed fetcher: const fetcher = (url: string) => fetch(url).then(r => r.json()) as Promise
  • Pass a stable key — string or array. Null/undefined/falsy key skips the request
  • Destructure fully: const { data, error, isLoading, isValidating, mutate } = useSWR(key, fetcher)
  • Distinguish isLoading (no data yet) from isValidating (revalidating with existing data)

Key Patterns

  • Use array keys for parameterized requests: useSWR(['/api/users', page], fetcher)
  • Conditional fetching: useSWR(userId ? /api/users/${userId} : null, fetcher)
  • Use useSWR(() => /api/users/${userId}) — function keys throw to pause on missing deps
  • Keep keys deterministic — same params = same key = shared cache

Configuration

  • Set global config via SWRConfig at app root for shared fetcher and options
  • Set revalidateOnFocus: false for data that rarely changes (settings, profiles)
  • Use refreshInterval for polling: useSWR(key, fetcher, { refreshInterval: 5000 })
  • Use dedupingInterval (default 2s) to prevent duplicate requests from multiple components

Mutations

  • Use the bound mutate for local mutations: const { mutate } = useSWR(key, fetcher)
  • Optimistic updates: mutate(newData, { optimisticData: newData, rollbackOnError: true, revalidate: true })
  • Use useSWRMutation for triggered mutations (POST/PUT/DELETE): const { trigger } = useSWRMutation(key, sendRequest)
  • Global mutate for cross-component invalidation: import { mutate } from 'swr'; mutate('/api/users')

Error Handling

  • Check error before rendering data — errors can coexist with stale data
  • Use onErrorRetry in config to customize retry logic (or disable for 4xx)
  • Display stale data with an error banner rather than replacing content with an error page
  • Set errorRetryCount to limit retries: { errorRetryCount: 3 }

Performance

  • Use useSWRInfinite for paginated/infinite scroll data
  • Preload data: preload(key, fetcher) on hover or route prefetch
  • Use the keepPreviousData option to prevent loading flicker during key changes
  • Avoid waterfalls: fetch independent data in parallel with separate useSWR calls

Read the full file on GitHub · 54 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 54 lines · 704 tokens per session scan A 79a045463ba9

Subscribe to this mod's changes

swr is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (38 stars, last pushed 9mo ago), licensed MIT. It adds 704 tokens to every session, about $0.0028 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

swr compared with cursor rules from other repositories

swr next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
swrnedcodes-ok/cursorrules-collectionCursor rule389mo agoMITA704Cursor
23-app-startuporbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
21-ads-billingorbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
30-screen-languageorbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
01-feature-checklistorbitalsonic/AndroidPilotCursor rule11mo agononeA36Cursor
06-coroutines-floworbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
09-resources-xmlorbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor