Async state management and data fetching library for web apps, with bindings for React, Vue, Svelte and Solid.
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
A React hooks library for building performant forms with state management and validation, for web and React Native.
An open multi-platform, multi-framework solution for building one app that runs on WeChat/Alipay/other mini programs, H5 web, and React Native using React or Vue.
A React and Tailwind CSS component library of animated UI components and effects that you copy into your Next.js or shadcn/ui apps.
A framework for building documentation websites with React.js, supporting Next.js, Astro, and Vite-based React frameworks.
Open-source Next.js-native headless CMS and app framework with a TypeScript backend and customizable React admin panel.