SWR

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

Library
npm
v2.5.1
32,495 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
81 /100 Excellent
Development Activity 76
Maintenance 84
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 90
Code Quality 88
Innovation 90
Learning Curve 85

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 43 apps in this directory

Python
64%
Other

Keep

Automation · Devops · Monitoring

12,433

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
88
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 1 weeks ago
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,338

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
63%
Apache 2.0

Laminar

AI Development · Monitoring

3,434

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 63%
Rust 35%
Updated 5 days ago
Python
53%
AGPL 3.0

LearnHouse

CMS · Learning Management

2,413

Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.

View details
90
Repo Health
77
Technical
65
Dependency
Built with
Python 53%
TypeScript 45%
Updated 5 days ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 5 days ago
TypeScript
98%
Other

LobeHub

AI Assistants · Automation · Productivity

83,455

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
98%
MPL 2.0

Logto

Authentication

14,769

Open-source auth infrastructure for SaaS and AI apps with OIDC, SAML, and RBAC

View details
92
Repo Health
83
Technical
63
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago

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