About this project
SWR is a React Hooks library for data fetching, named after the stale-while-revalidate cache invalidation strategy from HTTP RFC 5861. It first returns cached (stale) data, then revalidates by sending a request, and finally provides up-to-date data. With a single hook, it simplifies data fetching logic while offering speed, correctness, and stability. Key features include fast and lightweight reusable fetching, transport/protocol agnosticism, built-in cache and request deduplication, real-time updates, revalidation on focus and network recovery, polling, pagination with scroll position recovery, SSR/SSG support, local mutation (optimistic UI), smart error retry, TypeScript support, React Suspense, and React Native compatibility. Components receive a continuous stream of data updates automatically, keeping the UI fast and reactive. Quick start example: useSWR('/api/user', fetcher) returns data, error, and isLoading states. The fetcher can be any async function, allowing integration with preferred data-fetching libraries. Created by the Vercel team behind Next.js, with community contributions. Licensed under MIT.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.