{"schemaVersion":"1.0","record":{"label":"SWR","description":"MIT-licensed React data-fetching library with shared caching, revalidation and mutation helpers.","aliases":[],"kind":"software","website":"https://swr.vercel.app","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.","license":"MIT","lifecycle":"active","example":false,"features":[{"name":"Fetcher-independent data access","status":"supported","detail":"Application supplies fetcher logic; REST, GraphQL or other clients can be integrated.","useCase":"Fetching, refreshing and mutating server-backed data in React interfaces","platforms":["React applications"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://swr.vercel.app/docs/getting-started","locator":"React key/fetcher setup","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"}]},{"name":"Automatic refresh policies","status":"supported","detail":"Focus and network reconnect revalidate by default; intervals and immutable behavior are configurable.","useCase":"Fetching, refreshing and mutating server-backed data in React interfaces","platforms":["React applications"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://swr.vercel.app/docs/revalidation","locator":"Focus/reconnect defaults, intervals and immutable resources","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"}]},{"name":"Custom cache providers","status":"supported","detail":"Map-like providers scope cache behavior to an SWRConfig boundary.","useCase":"Fetching, refreshing and mutating server-backed data in React interfaces","platforms":["React applications"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://swr.vercel.app/docs/advanced/cache","locator":"Provider boundaries and global mutate limitations","retrievedAt":"2026-10-07T23:14:53Z","kind":"vendor"}]},{"name":"Optimistic UI and local rollback","status":"supported","detail":"Mutation helpers can show optimistic data and restore prior local cache on failure; this is not a server transaction rollback.","useCase":"Fetching, refreshing and mutating server-backed data in React interfaces","platforms":["React applications"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://swr.vercel.app/docs/mutation","locator":"Mounted-hook requirement, optimisticData, rollbackOnError and populateCache","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"}]},{"name":"Unsuccessful HTTP response detection","status":"limited","detail":"The fetcher must turn unsuccessful status codes into errors; parsed JSON alone does not establish success.","useCase":"Fetching, refreshing and mutating server-backed data in React interfaces","platforms":["React applications"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://swr.vercel.app/docs/error-handling","locator":"Fetcher rejection, HTTP status checks and data/error coexistence","retrievedAt":"2026-10-07T23:14:53Z","kind":"vendor"}]}],"alternatives":[],"slug":"swr","draftAlternatives":[{"targetSlug":"tanstack-query","status":"limited","detail":"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.","useCase":"Fetching, refreshing and mutating server-backed data in React interfaces","platforms":["React applications"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://swr.vercel.app/docs/getting-started","locator":"React key/fetcher setup","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/advanced/cache","locator":"Provider boundaries and global mutate limitations","retrievedAt":"2026-10-07T23:14:53Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/mutation","locator":"Mounted-hook requirement, optimisticData, rollbackOnError and populateCache","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server-state caching and query functions","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"}]}],"evidence":[{"url":"https://github.com/vercel/swr/blob/main/LICENSE","locator":"MIT terms","retrievedAt":"2026-10-07T23:14:37Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/getting-started","locator":"React key/fetcher setup","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/arguments","locator":"Entire key identity and changed fetcher context","retrievedAt":"2026-10-07T23:15:20Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/revalidation","locator":"Focus/reconnect defaults, intervals and immutable resources","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/error-handling","locator":"Fetcher rejection, HTTP status checks and data/error coexistence","retrievedAt":"2026-10-07T23:14:53Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/advanced/cache","locator":"Provider boundaries and global mutate limitations","retrievedAt":"2026-10-07T23:14:53Z","kind":"vendor"},{"url":"https://swr.vercel.app/docs/mutation","locator":"Mounted-hook requirement, optimisticData, rollbackOnError and populateCache","retrievedAt":"2026-10-07T23:15:02Z","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server-state caching and query functions","retrievedAt":"2026-10-07T23:13:58Z","kind":"vendor"}],"document":{"version":1,"references":[{"url":"https://github.com/vercel/swr/blob/main/LICENSE","locator":"MIT terms","retrievedAt":"2026-10-07T23:14:37Z","id":"license","title":"SWR license","kind":"vendor"},{"url":"https://swr.vercel.app/docs/getting-started","locator":"React key/fetcher setup","retrievedAt":"2026-10-07T23:13:58Z","id":"start","title":"SWR getting started","kind":"vendor"},{"url":"https://swr.vercel.app/docs/arguments","locator":"Entire key identity and changed fetcher context","retrievedAt":"2026-10-07T23:15:20Z","id":"arguments","title":"SWR arguments","kind":"vendor"},{"url":"https://swr.vercel.app/docs/revalidation","locator":"Focus/reconnect defaults, intervals and immutable resources","retrievedAt":"2026-10-07T23:15:02Z","id":"revalidation","title":"SWR automatic revalidation","kind":"vendor"},{"url":"https://swr.vercel.app/docs/error-handling","locator":"Fetcher rejection, HTTP status checks and data/error coexistence","retrievedAt":"2026-10-07T23:14:53Z","id":"errors","title":"SWR error handling","kind":"vendor"},{"url":"https://swr.vercel.app/docs/advanced/cache","locator":"Provider boundaries and global mutate limitations","retrievedAt":"2026-10-07T23:14:53Z","id":"cache","title":"SWR cache providers","kind":"vendor"},{"url":"https://swr.vercel.app/docs/mutation","locator":"Mounted-hook requirement, optimisticData, rollbackOnError and populateCache","retrievedAt":"2026-10-07T23:15:02Z","id":"mutation","title":"SWR mutation and revalidation","kind":"vendor"},{"url":"https://tanstack.com/query/latest/docs/framework/react/overview","locator":"Server-state caching and query functions","retrievedAt":"2026-10-07T23:13:58Z","id":"query","title":"TanStack Query overview","kind":"vendor"}],"overviewCitations":["start","cache","mutation"],"licenseCitations":["license"],"sections":[{"id":"fetcher","heading":"Separating fetching from cache behavior","paragraphs":[{"id":"fetcher-detail","content":[{"text":"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."}],"citations":["start"]}]},{"id":"keys","heading":"Keys must describe the changing request","paragraphs":[{"id":"keys-detail","content":[{"text":"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."}],"citations":["arguments"]}]},{"id":"refresh","heading":"Refresh policy and request volume","paragraphs":[{"id":"refresh-detail","content":[{"text":"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."}],"citations":["revalidation"]}]},{"id":"errors","heading":"Stale data can coexist with an error","paragraphs":[{"id":"errors-detail","content":[{"text":"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."}],"citations":["errors"]}]},{"id":"cache-scope","heading":"Custom caches change mutation scope","paragraphs":[{"id":"cache-scope-detail","content":[{"text":"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."}],"citations":["cache"]}]},{"id":"mutations","heading":"Optimistic updates are provisional","paragraphs":[{"id":"mutations-detail","content":[{"text":"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."}],"citations":["mutation"]}]},{"id":"fit","heading":"License and substitution","paragraphs":[{"id":"fit-detail","content":[{"text":"SWR uses MIT terms. It can replace "},{"text":"TanStack Query","targetSlug":"tanstack-query"},{"text":" 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."}],"citations":["license","start","query","cache"]}]}]},"id":"Q901","revision":949,"updatedAt":"2026-10-13T14:42:02Z","sourceUrl":"https://substitutefor.net/entities/Q901?revision=949"}}