swr
by
vercel

Description: React Hooks for Data Fetching

View on GitHub ↗

Summary Information

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

Issue Activity (beta)

Open issues: 112
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 638 days
Stale 30+ days: 111
Stale 90+ days: 104

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.

Repository Insights (GitGenius)

Median issue/PR response: 42.3 days
Mean response time: 341.1 days
90th percentile: 1192.9 days
Tracked items: 157

Most active contributors

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.

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.

swr
by
vercelvercel/swr

Repository Details

Fetching additional details & charts...