SWR

React Hooks for data fetching with built-in caching, revalidation, and real-time updates

Library
npm
v2.5.1
32,458stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity84
Maintenance92
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
88/100Excellent
Architecture90
Code Quality88
Innovation90
Learning Curve85

SWR is a lightweight React Hooks library for remote data fetching, created by the team behind Next.js at Vercel. The name derives from stale-while-revalidate (HTTP RFC 5861): it returns cached data first, fires the request to revalidate, and delivers the up-to-date result, keeping UIs fast and reactive.

With a single useSWR hook you get request deduplication, focus and network revalidation, polling, pagination, optimistic local mutation, smart error retry, SSR/SSG support, and React Suspense — all transport- and protocol-agnostic so it works with any async fetcher.

What You Get

  • A single useSWR hook that returns data, error, isLoading, isValidating, and a bound mutate
  • Built-in cache with automatic request deduplication across components sharing a key
  • Automatic revalidation on focus, network reconnect, and configurable interval polling
  • Optimistic local mutation and cache updates via mutate and useSWRMutation
  • Specialized entry points for infinite/paginated loading, immutable data, subscriptions, and mutations

Common Use Cases

  • Fetching and displaying API data in React components without manual loading/error state wiring
  • Keeping dashboards and feeds fresh with focus/reconnect revalidation and polling
  • Building infinite scroll and paginated lists with useSWRInfinite
  • Optimistic UI updates for forms and actions using useSWRMutation and mutate

Under The Hood

Architecture — SWR is organized as a small core (src/_internal) plus thin feature entry points (src/index, src/infinite, src/immutable, src/subscription, src/mutation). The main useSWR hook in src/index/use-swr.ts subscribes to a keyed global cache through React’s useSyncExternalStore (via the use-sync-external-store shim), so many components sharing a key read one cache slot and re-render only on relevant state changes. A global state map tracks per-key revalidators, timestamps, and in-flight promises to power deduplication, while a middleware pipeline (with-middleware, middleware-preset) wraps the hook to add features like immutability and infinite loading without touching the core.

Tech Stack — Written in TypeScript (99.5% of the codebase) targeting React 16.11–19 as a peer dependency, with only two tiny runtime dependencies: dequal for deep equality and use-sync-external-store for concurrent-safe store subscription. It builds with bunchee, transpiles via SWC, and ships dual ESM/CJS plus React Server Component (react-server) bundles through the package exports map.

Code Quality — The repo has an extensive test suite: 38 entries under test/ including unit, type, and Playwright e2e directories, with focused files covering caching, error retry, focus/reconnect revalidation, suspense, concurrency, and infinite loading. Code is strictly typed, linted with oxlint and formatted with oxfmt, and husky/lint-staged enforce checks on commit. Internal utilities are small, single-purpose modules (hashing, serialization, arg normalization) that keep the core hook readable.

API Design — The public API is deliberately minimal: useSWR(key, fetcher, options) returns a typed SWRResponse and covers the common case in one line, while advanced needs are opt-in via separate imports (swr/infinite, swr/mutation, swr/immutable, swr/subscription). Being fetcher-agnostic keeps boilerplate near zero, the naming is consistent and discoverable, and full TypeScript inference plus thorough documentation at swr.vercel.app make the ramp-up gentle.

Used by 42 apps in this directory

TypeScript
88%
Other

AFFiNE

Productivity · Project Management · Note Taking

71,668

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript88%
Updated today
TypeScript
59%
Other

agenta

Developer Tools · Devops · AI Development

4,489

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript59%
Python39%
Updated today
TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

32,102

Free, open-source Cowork desktop app that unifies Claude Code, Codex, Gemini CLI, and 20+ AI agents into a single platform with multi-agent teams, 24/7 cron automation, and zero-config built-in agent.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript95%
Updated today
TypeScript
72%
AGPL 3.0

APITable

Low Code Platforms · Databases

15,526

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
53
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated 9 months ago
Go
60%
Apache 2.0

Apache Answer

Community

15,652

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
85
Repo Health
78
Technical
69
Dependency
Built with
Go60%
TypeScript36%
Updated 2 days ago
Rust
86%
Other

Arroyo

Data Engineering · Analytics

5,005

A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.

View details
86
Repo Health
74
Technical
62
Dependency
Built with
Rust86%
Updated 1 weeks ago
TypeScript
49%
AGPL 3.0

BrowserOS

Browser · AI Assistants

13,248

The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.

View details
87
Repo Health
82
Technical
69
Dependency
Built with
TypeScript49%
Rust22%
Python16%
Updated today
TypeScript
97%
AGPL 3.0

Checkmate

Devops · Analytics · Monitoring

10,556

Self-hosted uptime and infrastructure monitoring with multi-protocol checks, global geo-coverage, and beautiful real-time dashboards.

View details
91
Repo Health
82
Technical
69
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

50,753

All-in-one AI desktop client with 300+ assistants and multi-model support

View details
88
Repo Health
84
Technical
71
Dependency
Built with
TypeScript99%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search