SWR is a React Hooks library for data fetching developed by the team behind Next.js at Vercel. The name derives from the stale-while-revalidate cache invalidation strategy defined in HTTP RFC 5861, which describes an approach where cached data is returned immediately while a revalidation request occurs in the background, ultimately providing updated data once available. This strategy enables applications to prioritize responsiveness by serving stale data instantly rather than waiting for fresh data from the network.
The library centers on a single primary hook called useSWR, which accepts a key (typically a URL) and a fetcher function as parameters. The fetcher is an asynchronous function responsible for retrieving data, and the hook returns three values: data, isLoading, and error. During the initial fetch, data remains undefined while isLoading is true. Once the request completes, the hook updates these values and triggers a component rerender. The fetcher function is transport and protocol agnostic, allowing developers to use any asynchronous data-fetching approach they prefer.
According to GitGenius activity tracking across 157 issues and pull requests, the repository maintains a median response latency of 1015.1 hours with a mean of 8186.7 hours. The most frequently labeled issues relate to bugs (12 occurrences), reproduction needed (9 occurrences), and typing-related concerns (7 occurrences). The most active contributors tracked by GitGenius are promer94 with 31 events, shuding with 21 events, and koba04 with 16 events. The repository shows overlapping contributors with microsoft/vscode, microsoft/typescript, and rust-lang/rust according to GitGenius analysis.
SWR provides extensive built-in functionality beyond basic data fetching. The library includes automatic request deduplication and caching mechanisms to reduce redundant network calls. It supports revalidation on focus and network recovery, enabling applications to refresh data when users return to the browser tab or regain connectivity. Additional features include polling for continuous updates, pagination support with scroll position recovery, server-side rendering and static site generation compatibility, local mutation for optimistic UI updates, and intelligent error retry logic. The library also supports React Suspense for declarative data loading states and works with React Native for mobile applications.
Written in TypeScript, SWR emphasizes performance and stability. The library is designed to be fast and lightweight while enabling components to receive continuous data updates automatically, resulting in UIs that remain responsive and reactive. The project is distributed under the MIT License and maintains comprehensive documentation at swr.vercel.app, which includes examples and detailed API references for developers implementing the library in their projects.