SWR Data Fetching
swr.vercel.app
1
Leaving SiteNav
External Link Disclaimer
You are about to visit swr.vercel.app. This website is not operated by us. We are not responsible for its content or privacy practices.
About this website
SWR is a React Hooks library for remote data fetching created by ZEIT, now Vercel, in 2019, whose name derives from stale-while-revalidate, an HTTP cache invalidation strategy popularized by RFC five eight six one, providing a fast, lightweight, and well-tested approach to data fetching in React applications with built-in caching, revalidation, focus tracking, reconnection, pagination, and mutation support, adopted by Vercel, GitHub, and thousands of production applications. The core useSWR hook accepts a unique key identifying the request and a fetcher function, returning data, error, and loading state, automatically deduplicating identical requests within the same render cycle, caching responses by key for instant rendering on subsequent renders, and revalidating data on window focus, network reconnection, and periodic intervals to keep the displayed data fresh without manual refresh logic. The optimistic UI and mutation capabilities enable updating the local cache immediately before the server confirms the change, providing instant feedback to user actions, with rollback on error and automatic revalidation after mutation to ensure consistency between the cache and server state. The infinite scrolling support through useSWRInfinite handles pagination and load-more patterns with cursor-based or offset-based pagination, while the suspense mode integrates with React Suspense boundaries for cleaner loading state management. The middleware support enables request transformation, logging, and custom caching strategies. The fallback data enables SSR and SSG hydration. The Laravel-style global configuration through SWRConfig. Designed for React developers.
Statistics
1
Views
0
Clicks
0
Like
0
Dislike