On this page
Overview
SWR is a React data-fetching hook library built around the stale-while-revalidate pattern. It can return cached data first, revalidate in the background, and update components with fresh results while also covering request deduplication, focus and network revalidation, polling, pagination, and optimistic updates.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Return cached data first and revalidate in the background
Pass a request key and asynchronous fetcher to useSWR to reuse cached values, trigger revalidation when needed, and update the component when fresh data arrives.
Sources: [2]
Centralize revalidation, deduplication, and mutation behavior
Focus recovery, network recovery, polling, pagination, retries, and local mutation can move into a shared hook and cache layer instead of being reimplemented by each screen.
Sources: [2]
Best fit
Fits React interfaces that need shared caching and refresh behavior for API data
It is useful for profiles, dashboards, lists, and detail views where multiple components consume the same remote data and should share loading, errors, caching, and revalidation rules.
Sources: [2]
Before adoption
Define request keys and fetcher responsibilities deliberately
SWR does not force a particular HTTP client. Applications provide the fetcher, while the key also identifies cached data, so parameterized requests need stable keys that uniquely represent the requested resource.
Sources: [2]
Official sources
- [1]vercel/swr repository(2026-09-30)
- [2]SWR v2.5.1 README(2026-09-30)
- [3]SWR v2.5.1 package metadata(2026-09-30)
- [4]SWR v2.5.1 release(2026-09-30)
- [5]SWR MIT license(2026-09-30)
- [6]SWR main package metadata(2026-09-30)
Supplemental curator note
SWR is most useful when multiple React surfaces should share caching and refresh rules instead of reimplementing them per component. Because request keys also define cache identity, parameterized requests benefit from a deliberate key strategy.
Try it in 3 steps
- 1
Install SWR 2.5.1
Add the latest stable release to an existing React project with the version pinned.
npm install swr@2.5.1 - 2
Define a fetcher
SWR does not force an HTTP client, so provide an application fetcher that accepts the key and returns a Promise.
const fetcher = (url) => fetch(url).then((res) => res.json()); - 3
Fetch data with useSWR
After importing useSWR from swr, pass the request key and fetcher and inspect data, loading, and error state.
const { data, error, isLoading } = useSWR('/api/user', fetcher);
Growth
Growth trends · Last 30 days
32,494 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 4
- Open PRs
- 77
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- react
- hook
- data-fetching
- swr
- suspense
- react-native
- fetch
- vercel
- stale-while-revalidate
- hooks
- nextjs
- data
- Stars
- 32,494
- Forks
- 1,384
- Watchers
- 216
- Open issues
- 149
- Contributors
- 198
- Owner type
- Organization
- Primary language
- TypeScript
- License
- MIT
- Repository last updated
- Sep 22, 2026
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- Medusa36,513 Stars
3 shared tag(s) · Same language
Compose commerce modules, workflows, and Store/Admin APIs into custom TypeScript commerce systems
TypeScript - Stripe Node.js Library4,521 Stars
2 shared tag(s) · 2 shared category(s) · Same language
Call Stripe APIs from server-side JavaScript/TypeScript with typed resources, retries, and webhook helpers
TypeScript - Firecrawl186,649 Stars
2 shared tag(s) · 1 shared category(s) · Same language
a web context API for search, scraping, crawling, and browser interaction
TypeScript - shadcn/ui124,865 Stars
2 shared tag(s) · 1 shared category(s) · Same language
copy component source into a project and grow it into your own UI library
TypeScript - Supabase110,871 Stars
2 shared tag(s) · 1 shared category(s) · Same language
Build on Postgres with integrated Auth, REST/GraphQL APIs, Realtime, Storage, and Functions
TypeScript - Tailwind CSS97,733 Stars
2 shared tag(s) · 1 shared category(s) · Same language
Compose utility classes in HTML and components and generate the required CSS at build time
TypeScript
Report incorrect information
Tell us if any listing information is incorrect or outdated.