Repolode
vercel

vercel/swr

A React Hooks library for data fetching that returns cached data first, then revalidates it in the background.

Stars
32,496
Forks
1,401
Open issues
241
Last commit
4 days ago

What is it?

SWR is a React Hooks library for data fetching. Its name comes from stale-while-revalidate, a cache strategy from HTTP RFC 5861: the hook first returns cached (stale) data, sends the request to revalidate it, and then updates the component with the latest result.

You call a single hook, `useSWR`, with a key (usually an API URL) and a fetcher function. It returns `data`, `error` and `isLoading`, and the component re-renders when the data changes. The fetcher can be any asynchronous function, so you can use your own data-fetching library for that part.

The library includes a built-in cache with request deduplication, revalidation on focus and network recovery, polling, pagination helpers, SSR and SSG support, optimistic local mutation, error retry, TypeScript types, and React Suspense support. It also works with React Native.

Key features

  • 01Built-in cache with request deduplication
  • 02Revalidates on focus and on network recovery
  • 03Polling and real-time data updates
  • 04Optimistic local mutation for instant UI updates
  • 05Supports SSR, SSG, TypeScript and React Suspense

Use cases

  • Fetching and caching API data in a React or Next.js app
  • Keeping dashboards or feeds up to date with polling or revalidation
  • Building optimistic UIs for forms and edits
  • Sharing data across components in a React Native app

Topics

FAQ

What is swr?
A React Hooks library for data fetching that returns cached data first, then revalidates it in the background. SWR is a React Hooks library for data fetching. Its name comes from stale-while-revalidate, a cache strategy from HTTP RFC 5861: the hook first returns cached (stale) data, sends the request to revalidate it, and then updates the component with the latest result.
Is swr free to use? What license does it have?
swr is open source under the MIT license. Check the license terms before using it in commercial products.
Is swr still maintained?
Actively maintained. The last commit to swr was on Oct 16, 2026.
What can I use swr for?
Fetching and caching API data in a React or Next.js app Keeping dashboards or feeds up to date with polling or revalidation Building optimistic UIs for forms and edits Sharing data across components in a React Native app
Where can I get swr?
The source code and installation instructions are on GitHub: https://github.com/vercel/swr

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects