// the find
vercel/swr
React Hooks for Data Fetching
SWR is a React data-fetching hook that implements the stale-while-revalidate pattern: show cached data immediately, then rehydrate in the background. It handles deduplication, focus/network revalidation, and pagination out of the box. The target audience is React developers who want something between a raw fetch call and a full server-state manager like React Query.
Request deduplication is built into the cache layer — multiple components hitting the same key in a render cycle share one in-flight request, which is correct behavior most libraries get wrong. The fetcher abstraction is genuinely protocol-agnostic: you pass any async function, which means GraphQL, REST, or even IndexedDB reads all work identically. The `useSWRInfinite` pagination model maps naturally to cursor-based APIs, and the `preload` API added in later versions lets you kick off fetches before the component even mounts. TypeScript support is first-class and the types correctly thread through the fetcher return type to `data` without needing manual annotation.
Cache invalidation across unrelated keys requires either manual `mutate` calls with the exact key or a tag-based invalidation system that SWR doesn't have — React Query's `invalidateQueries` by tag is more ergonomic for complex apps. The global SWRConfig context means misconfiguration (wrong fetcher, wrong deduplication interval) silently applies everywhere, and debugging why a component got stale data is harder than it should be. Error handling is opt-in at the component level, so if you forget to check the `error` field you get a silent failure with no UI feedback — there's no way to set a global error boundary at the SWR layer. The Suspense integration still has rough edges around error boundaries and retry behavior, as evidenced by the `suspense-retry` examples needing their own dedicated e2e test suite.