Open-source project
vercel/swr avatar
vercel/swr

SWR's exports map has no react-server entry for immutable or subscription

GitHub describes it as React Hooks for Data Fetching. The repository metadata lists TypeScript as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.

32,495 stars1,404 forksTypeScriptMIT

At a glance

What is it?
SWR is a React hooks library for remote data fetching built around a stale-while-revalidate cache, and it hands the request itself to a fetcher you supply. Revalidation on focus and polling are demonstrated in the examples rather than in the Quick Start, and its immutable and subscription export subpaths carry no react-server condition.
Who is it for?
SWR suits a React application where one hook should own caching, request deduplication and revalidation, and where you would rather not stand up a query provider. It does not suit a codebase that needs a react-server build of `swr/immutable` or `swr/subscription`, and the two libraries answer the same problem with different models, so pick on the model rather than on the feature list.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 38 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • vercel/swr32,495 ★ · +41
Star history
Repository2026-08-132026-11-23
vercel/swr32.5k32.5k

41 Stars in the last 102 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

useSWR takes a key and a fetcher, and gives back three values

The README has no install command. It goes straight from the package name on npm to an import, and the shortest useful example is a component that pulls three values out of one hook:

js
import useSWR from 'swr'

function Profile() {
  const { data, error, isLoading } = useSWR('/api/user', fetcher)

  if (error) return <div>failed to load</div>
  if (isLoading) return <div>loading...</div>
  return <div>hello {data.name}!</div>
}

The two arguments have distinct jobs. The `key` is a unique identifier for the request, normally the URL of the API, and it is also the cache address, which is why the same URL in two components shares one result instead of firing two requests. The `fetcher` takes that key as its parameter and returns data asynchronously, and the README is explicit that it can be any asynchronous function, so your usual data-fetching library can sit behind it.

The name comes from `stale-while-revalidate`, a cache invalidation strategy popularized by HTTP RFC 5861: return what the cache holds, send the request, come back with the current answer.

Distinguish initial loading from revalidation

The quick-start example destructures `data`, `error` and `isLoading`, but the hook returns additional values. `isLoading` indicates a request is in progress without loaded data; `isValidating` also signals background revalidation when existing data is available. The `mutate` API updates or revalidates the cache. Handle errors explicitly, and check the official state-machine documentation for fallback and previous-data behavior.

Focus revalidate and polling are separate example directories

The feature list names a lot at once, including revalidation on focus, revalidation on network recovery, polling, pagination with scroll position recovery, built-in smart error retry, SSR and SSG, optimistic UI, React Suspense and React Native. None of that appears in the Quick Start.

The examples directory is where the features are demonstrated. `focus-revalidate` and `refetch-interval` are separate directories, `storage-tab-sync` covers state shared across browser tabs, `suspense`, `suspense-global` and `suspense-retry` split the Suspense integration three ways, and `infinite` and `infinite-scroll` cover pagination. `optimistic-ui` and `optimistic-ui-immer` are two versions of the same demo.

The Quick Start shows only the key, the fetcher and the three returned values; the other features on the list are demonstrated in the examples directory. `_internal/` and the `src/` tree are the implementation, and the README does not enumerate the configuration surface at all.

Four subpaths, and the react-server condition stops after the second

The exports map in package.json is the part worth reading before you choose an import. The subpaths include `.`, `./infinite`, `./immutable` and `./subscription`. The first two declare a `react-server` condition: `.` points at `react-server.d.mts` and `react-server.mjs`, and `./infinite` at `react-server.mjs`. The other two declare only `import` and `require`.

So `swr/immutable` and `swr/subscription` have no server-component build.

Two smaller details in the same block matter. `sideEffects` is false, so a bundler can drop what you do not import. And the top-level `types` field points at `./dist/index/index.d.ts`, the CommonJS declaration file, while the `import` condition serves `./dist/index/index.d.mts`. A project on classic node resolution and one on the exports map therefore type-check against different files.

The subpath entry points are real directories at the repository root

The layout explains the shape of the package. `infinite/`, `immutable/`, `subscription/` and `mutation/` sit at the top level next to `src/`, each one a subpath you can import, and `_internal/` holds whatever they share. That is four packages' worth of surface in one repository rather than one entry point with options.

The root holds two Jest configurations, `jest.config.js` and `jest.config.build.js`.

The rest of the tooling is visible in the root. `.swcrc` says the transpiler is SWC, `.oxlintrc.json` and `.oxfmtrc.json` are the lint and format configs, `.husky/` holds git hooks, and `vercel.json` is the deployment config for the site linked from the README. `pnpm-workspace.yaml` and `pnpm-lock.yaml` make this a pnpm workspace, with `packageManager` set to [email protected].

The default branch holds 2.6.0-beta.0, and 2.5.1 is the last stable

Three tags tell the release story: v2.5.0 on 2026-08-03, v2.5.1 on 2026-08-12, and v2.6.0-beta.0 on 2026-09-22. The version field in package.json reads `2.6.0-beta.0`, and the last push was on 2026-10-16, after that tag. So the default branch, `main`, is sitting on a prerelease of the next minor rather than on the 2.5.x line.

That matters if you build from source rather than from npm, because cloning `main` gives you prerelease code and the README makes no distinction between the two. The last push date is recent, so the branch is not stale, but recent and stable are different claims and only one of them applies to a beta tag.

A second, smaller thing: the README points to Next.js as the team behind the library and lists Shu Ding, Jiachi Liu, Guillermo Rauch, Joe Haddad and Paco Coursey as authors, all at Vercel, with a credit to Ryan Chen for the `swr` npm package name. Licence is MIT, so the commercial terms are not a consideration for an internal tool.

The fetcher is the seam, and that is where a different library goes

The README states that the fetcher can be any asynchronous function and that you can use your favourite data-fetching library to handle that part. Transport and protocol agnostic is on the feature list for the same reason. SWR owns the cache, the deduplication and the revalidation, and it does not own the request.

That is the seam to compare on. A library built around an explicit query object and an invalidation API, which is how React Query and TanStack Query are generally described, puts a named cache of queries in front of the component and makes you say what should be stale. SWR uses a key and fetcher, supports automatic revalidation, and also exposes `mutate` for explicit cache updates and revalidation. Neither description appears in this repository, which does not compare itself to any of them.

For an application whose only requirement is a key and a fetcher, the smaller model is the one you want. For anything that needs to invalidate named queries, run a mutation queue, or reason about garbage collection, the two approaches cost different amounts of code.

Editorial conclusion

SWR suits a React application where one hook should own caching, request deduplication and revalidation, and where you would rather not stand up a query provider. It does not suit a codebase that needs a react-server build of `swr/immutable` or `swr/subscription`, and the two libraries answer the same problem with different models, so pick on the model rather than on the feature list. Verify three things before adopting: whether your module resolution reads the exports map or the top-level `types` field, because they point at different declaration files; whether you are installing 2.5.1 or the 2.6.0 beta that the default branch holds; and whether you need `swr/immutable` or `swr/subscription` on a react-server condition, since neither declares one.

Frequently asked questions

Which is better, SWR or React Query?

The repository does not compare them. The difference in approach is that useSWR takes a key and a fetcher and revalidates on its own triggers, while a query-and-invalidation library keeps a named collection of queries that you explicitly mark as stale. Judge by which model your application already has, not by the feature lists.

What is Vercel SWR?

SWR is a React Hooks library for data fetching, described in its package.json as a React Hooks library for remote data fetching. It is created by the team behind Next.js and the README names stale-while-revalidate, the cache invalidation strategy popularized by HTTP RFC 5861, as the source of the name.

What does SWR stand for and what does the name mean?

The name derives from `stale-while-revalidate`. The strategy returns the data already in cache first, then sends the request, then comes back with the up-to-date data, so a component renders with something immediately rather than with nothing.

Which entry points does the swr package export?

The exports map lists, among others, `.`, `./infinite`, `./immutable` and `./subscription`. Only the first two declare a `react-server` condition, `.` pointing at `react-server.d.mts` and `react-server.mjs` and `./infinite` at `react-server.mjs`, while the other two declare only `import` and `require`.

What values does useSWR return?

The hook exposes data, error, isLoading, isValidating and mutate among its return values. isLoading indicates an ongoing request without loaded data; isValidating also covers background revalidation.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/vercel-swr.svg)](https://hysenlabs.com/projects/vercel-swr)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/vercel-swr.svg)](https://hysenlabs.com/projects/vercel-swr)

Was this useful?