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.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
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
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
Authentication
No authentication — data fetching library. Auth headers are added by the fetcher function provided to SWR.
Pricing
MIT licensed. Completely free. Made by Vercel.
Agent Metadata
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.
Scores are editorial opinions as of 2026-03-06.