vercel/swr

Created Feb 21, 2021 · View the vercel/swr repository page

React Hooks for Data Fetching

Want this for your repo?

Render a free sample of any GitHub repo in seconds.

Visualize your own →

Contributors

99

Lines of Code

738

From

Oct 28, 2019

To

Feb 14, 2021

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

More from vercel

See all →