substitutefor

software · Q901

SWR

MIT-licensed React data-fetching library with shared caching, revalidation and mutation helpers.

Suggest a correction

Overview

SWR is an open-source React library for data fetching and caching. A component supplies a key and a fetcher, while SWR coordinates cached data and refresh behavior. Mutation helpers support updating the interface around remote writes. It supplies client data-state machinery, not a backend or proof that an optimistic UI change has been saved.[2][6][7]

Separating fetching from cache behavior

SWR accepts application-defined fetcher logic, with the introductory guide showing a native fetch wrapper and alternatives for other request clients. This lets the same hook pattern work with different APIs. The application still owns transport details and how a response becomes useful data; the library does not discover an API's business rules merely from a URL.[2]

Keys must describe the changing request

The arguments guide warns that a request using changing authorization context while retaining a fixed key can return the wrong cached data. The key must capture the dependencies that distinguish results. It also documents changed array-argument behavior between older versions and version 2 onward. Existing fetcher signatures and context-sensitive keys should therefore be reviewed together when migrating generated or older code.[3]

Refresh policy and request volume

SWR revalidates on window focus and network reconnection by default. Timed refreshing is optional, with hidden and offline refresh controls disabled by default. An immutable-resource helper disables automatic revalidation for data that really should not change. As an assessment, these settings should match the resource and service limits; disabling refresh for changing account data is a behavior change, not simply a harmless optimization.[4]

Stale data can coexist with an error

A fetcher rejection produces an error state. The error-handling guide explicitly checks non-success HTTP statuses and throws rather than assuming valid JSON means success. It also notes that data and error can be present simultaneously, allowing the UI to retain an existing result while reporting a failed refresh. Retry behavior is configurable. A generated component needs to decide how that stale-but-visible state should look.[5]

Custom caches change mutation scope

The default shared cache can be replaced with a Map-like provider under SWRConfig. Hooks inside that boundary use that provider, and the globally imported mutate does not operate on them in the same way. The documentation points to useSWRConfig for the relevant scoped mutator and discourages direct cache writes. Remounting a provider can also recreate its cache, so its placement affects more than code organization.[6]

Optimistic updates are provisional

Mutation helpers can display optimistic data, populate the cache from a response and restore prior local data when a remote operation fails. That rollback changes the local cache; it does not establish reversal of a completed server operation. The guide also warns that calling a global mutator with only a key does not revalidate or update the cache unless a matching hook is mounted. These are important boundaries for generated save buttons and background update flows.[7]

License and substitution

SWR uses MIT terms. It can replace TanStack Query for suitable React server-data workflows if the application migrates its keys, fetchers, cache boundaries and refresh policy. This comparison does not establish API compatibility or replace the backend's persistence and authorization rules. No installation, performance test or application migration was performed.[1][2][6][8]

Capabilities & limitations

Fetcher-independent data access

supported

Application supplies fetcher logic; REST, GraphQL or other clients can be integrated.[2]

Fetching, refreshing and mutating server-backed data in React interfaces · React applications · Version, build and integration requirements apply

1 source · check evidence
https://swr.vercel.app/docs/getting-started

React key/fetcher setup

vendor · checked 2026-10-07

Automatic refresh policies

supported

Focus and network reconnect revalidate by default; intervals and immutable behavior are configurable.[4]

Fetching, refreshing and mutating server-backed data in React interfaces · React applications · Version, build and integration requirements apply

1 source · check evidence
https://swr.vercel.app/docs/revalidation

Focus/reconnect defaults, intervals and immutable resources

vendor · checked 2026-10-07

Custom cache providers

supported

Map-like providers scope cache behavior to an SWRConfig boundary.[6]

Fetching, refreshing and mutating server-backed data in React interfaces · React applications · Version, build and integration requirements apply

1 source · check evidence
https://swr.vercel.app/docs/advanced/cache

Provider boundaries and global mutate limitations

vendor · checked 2026-10-07

Optimistic UI and local rollback

supported

Mutation helpers can show optimistic data and restore prior local cache on failure; this is not a server transaction rollback.[7]

Fetching, refreshing and mutating server-backed data in React interfaces · React applications · Version, build and integration requirements apply

1 source · check evidence
https://swr.vercel.app/docs/mutation

Mounted-hook requirement, optimisticData, rollbackOnError and populateCache

vendor · checked 2026-10-07

Unsuccessful HTTP response detection

limited

The fetcher must turn unsuccessful status codes into errors; parsed JSON alone does not establish success.[5]

Fetching, refreshing and mutating server-backed data in React interfaces · React applications · Version, build and integration requirements apply

1 source · check evidence
https://swr.vercel.app/docs/error-handling

Fetcher rejection, HTTP status checks and data/error coexistence

vendor · checked 2026-10-07

Can substitute for

These are products or services this entry can replace. Check the task and limitations for each comparison.

TanStack Query for Fetching, refreshing and mutating server-backed data in React interfaces

limited

Can replace TanStack Query for React data fetching, caching and supported mutation flows after rewriting hooks and policies. Provider boundaries, key dependencies and refetch behavior must be explicitly migrated.[2][6][7][8]

React applications · Version, build and integration requirements apply

References

  1. SWR license

    MIT terms

    vendor · retrieved 2026-10-07
  2. SWR getting started

    React key/fetcher setup

    vendor · retrieved 2026-10-07
  3. SWR arguments

    Entire key identity and changed fetcher context

    vendor · retrieved 2026-10-07
  4. SWR automatic revalidation

    Focus/reconnect defaults, intervals and immutable resources

    vendor · retrieved 2026-10-07
  5. SWR error handling

    Fetcher rejection, HTTP status checks and data/error coexistence

    vendor · retrieved 2026-10-07
  6. SWR cache providers

    Provider boundaries and global mutate limitations

    vendor · retrieved 2026-10-07
  7. SWR mutation and revalidation

    Mounted-hook requirement, optimisticData, rollbackOnError and populateCache

    vendor · retrieved 2026-10-07
  8. TanStack Query overview

    Server-state caching and query functions

    vendor · retrieved 2026-10-07

Discussion & disputes

Ask about unclear claims or explain a concern with supporting sources. If you have a specific fix, suggest a correction.

No discussion yet.

Sign in with an active account to join the discussion.

Revision history

Open a revision to read an earlier version of this article.

RevisionTimestampEdit summary
9492026-10-13 14:42:02/* wbeditentity-create-item:0| */ sf:9d196f80-bd32-49ed-8a61-ab67edfbe06f:v1 | Adds SWR with key identity, fetcher error handling, custom-provider mutation scope and optimistic-cache rollback boundaries. | attribution: /proposals/9d196f80-bd32-49ed-8a61-ab67edfbe06f