github.com/vercel/swr

React Hooks for Data Fetching

Open this visualization on its own page →

Contributors

99

Lines of Code

738

From

2019-10-28

To

2021-02-14

About vercel/swr

SWR is a React Hooks library for data fetching created by the team behind Next.js. The name derives from "stale-while-revalidate," a cache invalidation strategy where the library returns cached data immediately while simultaneously fetching fresh data in the background. The `useSWR` hook accepts a unique key and a fetcher function, returning data, loading state, and error information to components.

The library emphasizes performance and simplicity, offering features like built-in caching, request deduplication, revalidation on focus and network recovery, polling, pagination, SSR and SSG support, local mutations for optimistic UI updates, and smart error retry logic. It works with any asynchronous fetcher function, making it transport and protocol agnostic, and supports React Suspense and React Native alongside standard React applications.

With SWR, React components receive continuous automatic data updates, keeping the UI fast and reactive. The library is built with TypeScript, lightweight, and designed to handle real-time experiences while significantly simplifying data-fetching logic across projects of any size.

Share this video