Sourcemap Explorer
Stack · npm package

swr

React Hooks library for remote data fetching

latest 2.5.0· MIT· 179 versions publishedView on npm

About

React Hooks library for remote data fetching

swrreacthooksrequestcachefetch

What detecting swr tells you about a site

swr reveals a Vercel-flavoured data-fetching strategy — stale-while-revalidate caching with React hooks — chosen for its tiny footprint and tight Next.js integration. Its presence is a strong hint the site is a Next.js app built by a team that preferred SWR's simplicity over the heavier React Query.

Why the exact swr version matters

SWR 2 added mutation and optimistic-update APIs and changed some hook signatures; the exact version tells you which caching and mutation contract the code relies on.

swr in a real-world stack

When you find swr in a bundle, it rarely travels alone. next (the two come from the same ecosystem), and a fetch layer underneath the hook.

Quick facts

Latest version2.5.0
LicenseMIT
Installnpm install swr
Direct dependencies2
Peer dependenciesreact

Common pairings

Packages this one expects to find in the same project. Each is also a Sourcemap Explorer detection target.

What swr pulls in

swr declares 2 direct dependencies — each one also rides into any bundle that ships swr, so they are detection targets too. Reading them is a quick way to understand the package's real footprint .

dequaluse-sync-external-store

How Sourcemap Explorer detects swr

swr ships as v2.5.0, published 2026-08-03 and carries 2 direct dependencies, 1 peer dependency (react), 179 versions on the registry. Those exact numbers are the footprint Sourcemap Explorer matches when swr rides inside a deployed bundle — here is how the detection works.

We catch swr from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/swr/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.

  1. 1

    Confirm the site exposes sourcemaps

    In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment — that map is where the `swr` paths live.

  2. 2

    Find the package in the bundle

    Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/swr/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/swr/package.json` gives you the exact installed version.

  3. 3

    Read the version directly from package.json

    Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/swr/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.

Major releases of swr

When each major version first landed. Major bumps are where breaking changes live, so this timeline is the fastest way to date the swr version a site actually ships against the ecosystem.

Major
First release
Date
v2
2.0.0
2022-12-09
v1
1.0.0
2021-08-27
v0
0.1.0
2018-04-06

Recent versions

Version
Released
2.5.0
2026-08-03
2.4.2
2026-06-22
2.4.1
2026-02-27
2.4.0
2026-02-01
2.3.8
2025-12-15
2.3.7
2025-11-28
2.3.6
2025-08-11
2.3.5
2025-08-09

swr README

Live mirror of the GitHub README, for reference. Updated whenever the repo's default branch changes.

SWR


Introduction

SWR is a React Hooks library for data fetching.

The name “SWR” is derived from stale-while-revalidate, a cache invalidation strategy popularized by HTTP RFC 5861. SWR first returns the data from cache (stale), then sends the request (revalidate), and finally comes with the up-to-date data again.

With just one hook, you can significantly simplify the data fetching logic in your project. And it also covered in all aspects of speed, correctness, and stability to help you build better experiences:

  • Fast, lightweight and reusable data fetching
  • Transport and protocol agnostic
  • Built-in cache and request deduplication
  • Real-time experience
  • Revalidation on focus
  • Revalidation on network recovery
  • Polling
  • Pagination and scroll position recovery
  • SSR and SSG
  • Local mutation (Optimistic UI)
  • Built-in smart error retry
  • TypeScript
  • React Suspense
  • React Native

...and a lot more.

With SWR, components will get a stream of data updates constantly and automatically. Thus, the UI will be always fast and reactive.


View full documentation and examples on swr.vercel.app.


Quick Start

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>
}

In this example, the React Hook useSWR accepts a key and a fetcher function. The key is a unique identifier of the request, normally the URL of the API. And the fetcher accepts key as its parameter and returns the data asynchronously.

useSWR also returns 3 values: data, isLoading and error. When the request (fetcher) is not yet finished, data will be undefined and isLoading will be true. When we get a response, it sets data and error based on the result of fetcher, isLoading to false and rerenders the component.

Note that fetcher can be any asynchronous function, you can use your favourite data-fetching library to handle that part.


View full documentation and examples on swr.vercel.app.


Authors

This library is created by the team behind Next.js, with contributions from our community:

Contributors

Thanks to Ryan Chen for providing the awesome swr npm package name!


License

The MIT License.

FAQ

What is swr used for?

React Hooks library for remote data fetching

How can I tell if a website is using swr?

Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `swr` from two complementary signals: `node_modules/swr/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.

How do I find out which version of swr a website is running?

Read it straight from the site's JavaScript sourcemap. When a build ships source maps, the bundled `swr/package.json` carries the exact `version` string — Sourcemap Explorer extracts it in one click on the Stack tab, and you can do it by hand in DevTools by opening the `.map` file and searching for `node_modules/swr/package.json`. That is far more reliable than inferring the version from an asset-hash or a `?ver=` query string, which is all surface-level detectors have to go on. The current npm release is 2.5.0, but real deployments frequently run an older pinned version — which is exactly why reading the bundled number matters.

What is the latest version of swr?

2.5.0, as published on the npm registry. The "Recent versions" table on this page lists the most recent 8 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.

Is swr actively maintained?

Very actively maintained — the last release shipped within the past three months. The last published release was 2026-08-03. Source code: https://github.com/vercel/swr.

Where can I read more?

Project homepage: https://swr.vercel.app. Source code: https://github.com/vercel/swr. Published on npm: https://www.npmjs.com/package/swr. Licensed as MIT.

Keep reading on Sourcemap Explorer

Detected by Sourcemap Explorer

When a bundle ships sourcemaps, we read the embedded package.json for swr and report the precise version (the registry's latest is v2.5.0, published 2026-08-03; the bundled copy is often older). Without sourcemaps, an import / require in the page's scripts is enough to flag it.

Install free on Chrome