vercel/swr

React Hooks for Data Fetching

View on GitHub ↗Jump to charts ↓Open shareable report

Summary Information

Updated 39 minutes ago
Added to GitGenius on April 9th, 2022
Created on October 28th, 2019
Open Issues & Pull Requests: 214 (+0)
Number of forks: 1,382
Total Stargazers: 32,468 (+0)
Total Subscribers: 212 (+0)

Repository Insights (GitGenius)

Median issue/PR response: 69.5 days
Mean response time: 333.7 days
90th percentile: 1192.9 days
Tracked items: 148

How this project is maintained

Around half of the issues opened in the past year never receive a reply. 95% of open issues come from outside the core team, so the backlog reflects real-world use rather than internal planning. Only 2% of issues opened in the past year have been closed. Three people close 53% of everything that gets resolved.

Charts & Analytics

Fetching additional details & charts...

Issue Activity (beta)

Open issues: 111
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 647 days
Stale 30+ days: 108
Stale 90+ days: 107

Recent activity

Opened in 7 days: 0
Closed in 7 days: 0
Comments in 7 days: 0
Events in 7 days: 0

Top labels

  • bug (42)
  • feature request (17)
  • reproduction needed (16)
  • discussion (15)
  • question (14)
  • area: typing (13)
  • good first issue (12)
  • area: mutation (10)

Most active issues this week

No issue events were indexed in the last 7 days.

Detailed Description

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.

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.