SWR

React data fetching library using the stale-while-revalidate (SWR) HTTP caching strategy. useSWR hook returns cached data immediately (stale), then fetches fresh data in the background (revalidate). Features: automatic revalidation on focus, interval polling, deduplication of concurrent requests, pagination, mutation, and optimistic updates. Lighter alternative to TanStack Query from Vercel — focused and minimal.

Evaluated Mar 06, 2026 (0d ago) v2.x
Homepage ↗ Repo ↗ Developer Tools react data-fetching caching stale-while-revalidate hooks vercel real-time typescript
⚙ Agent Friendliness
69
/ 100
Can an agent use this?
🔒 Security
92
/ 100
Is it safe for agents?
⚡ Reliability
88
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
90
Error Messages
82
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
95
Auth Strength
92
Scope Granularity
90
Dep. Hygiene
90
Secret Handling
95

Client-side caching library. No server communication from the library itself. Vercel-backed, MIT licensed. Cache is in-memory — no persistent storage security concerns.

⚡ Reliability

Uptime/SLA
90
Version Stability
88
Breaking Changes
85
Error Recovery
88
AF Security Reliability

Best When

You want simple, elegant data fetching with caching and revalidation in React without TanStack Query's complexity — simple CRUD apps and read-heavy UIs.

Avoid When

You need complex cache invalidation, background sync, dependent queries, or DevTools — TanStack Query offers a more feature-complete solution.

Use Cases

  • Fetch and cache API data in React with automatic revalidation on window focus and network reconnect
  • Implement optimistic updates where UI changes immediately while the API call completes in the background
  • Deduplicate concurrent API calls — multiple components using the same useSWR key share one request
  • Build real-time data refreshing with SWR's refreshInterval option for polling-based live data
  • Implement infinite scroll pagination using useSWRInfinite for loading additional pages on scroll

Not For

  • Complex server-state management with mutations, invalidation graphs, or devtools — use TanStack Query for advanced features
  • Non-React applications — SWR is React hooks only; use fetch/axios directly for other frameworks
  • Offline-first applications requiring complex cache persistence — TanStack Query's Persist plugin offers more sophisticated caching

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No authentication — data fetching library. Auth headers are added by the fetcher function provided to SWR.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT licensed. Completely free. Made by Vercel.

Agent Metadata

Pagination
cursor
Idempotent
Full
Retry Guidance
Documented

Known Gotchas

  • SWR key must be serializable — using objects as keys requires converting to strings (JSON.stringify) or using stable key tuples
  • Conditional fetching uses null as key — useSWR(condition ? key : null, fetcher) prevents fetching before data is ready
  • mutate() updates cache globally by key — all components using the same key see the update immediately
  • SWR doesn't batch mutations like TanStack Query — rapid consecutive mutations may cause race conditions
  • Error retry uses exponential backoff by default — configure onErrorRetry to customize or disable retry behavior
  • SWRConfig provider is needed for global configuration — without it, each useSWR has independent configuration

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for SWR.

$99

Scores are editorial opinions as of 2026-03-06.

5215
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered