{"id":13406280,"url":"https://github.com/vercel/swr","last_synced_at":"2025-05-12T15:08:08.755Z","repository":{"id":37033169,"uuid":"218115303","full_name":"vercel/swr","owner":"vercel","description":"React Hooks for Data Fetching","archived":false,"fork":false,"pushed_at":"2025-04-17T10:10:37.000Z","size":3504,"stargazers_count":31414,"open_issues_count":165,"forks_count":1265,"subscribers_count":219,"default_branch":"main","last_synced_at":"2025-05-05T11:11:29.670Z","etag":null,"topics":["cache","data","data-fetching","fetch","hook","hooks","nextjs","react","react-native","stale-while-revalidate","suspense","swr","vercel"],"latest_commit_sha":null,"homepage":"https://swr.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vercel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-10-28T18:16:01.000Z","updated_at":"2025-05-05T11:06:21.000Z","dependencies_parsed_at":"2024-01-02T00:00:01.745Z","dependency_job_id":"7cad17e1-29a8-43cb-98a8-3d0956ae9925","html_url":"https://github.com/vercel/swr","commit_stats":{"total_commits":878,"total_committers":187,"mean_commits":4.695187165775401,"dds":0.7801822323462415,"last_synced_commit":"1585a3e37d90ad0df8097b099db38f1afb43c95d"},"previous_names":["zeit/swr"],"tags_count":127,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fswr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fswr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fswr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fswr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vercel","download_url":"https://codeload.github.com/vercel/swr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252486917,"owners_count":21755835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","data","data-fetching","fetch","hook","hooks","nextjs","react","react-native","stale-while-revalidate","suspense","swr","vercel"],"created_at":"2024-07-30T19:02:26.087Z","updated_at":"2025-05-05T12:34:11.968Z","avatar_url":"https://github.com/vercel.png","language":"TypeScript","readme":"[![SWR](https://assets.vercel.com/image/upload/v1572289618/swr/banner.png)](https://swr.vercel.app)\n\n\u003cp align=\"center\"\u003e\n  \u003ca aria-label=\"Vercel logo\" href=\"https://vercel.com\"\u003e\n    \u003cimg src=\"https://badgen.net/badge/icon/Made%20by%20Vercel?icon=zeit\u0026label\u0026color=black\u0026labelColor=black\"\u003e\n  \u003c/a\u003e\n  \u003cbr/\u003e\n  \u003ca aria-label=\"NPM version\" href=\"https://www.npmjs.com/package/swr\"\u003e\n    \u003cimg alt=\"\" src=\"https://badgen.net/npm/v/swr\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"Package size\" href=\"https://bundlephobia.com/result?p=swr\"\u003e\n    \u003cimg alt=\"\" src=\"https://badgen.net/bundlephobia/minzip/swr\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"License\" href=\"https://github.com/vercel/swr/blob/main/LICENSE\"\u003e\n    \u003cimg alt=\"\" src=\"https://badgen.net/npm/license/swr\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\nSWR is a React Hooks library for data fetching.\n\nThe name “**SWR**” is derived from `stale-while-revalidate`, a cache invalidation strategy popularized by [HTTP RFC 5861](https://tools.ietf.org/html/rfc5861).\n**SWR** first returns the data from cache (stale), then sends the request (revalidate), and finally comes with the up-to-date data again.\n\nWith 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:\n\n- **Fast**, **lightweight** and **reusable** data fetching\n- Transport and protocol agnostic\n- Built-in **cache** and request deduplication\n- **Real-time** experience\n- Revalidation on focus\n- Revalidation on network recovery\n- Polling\n- Pagination and scroll position recovery\n- SSR and SSG\n- Local mutation (Optimistic UI)\n- Built-in smart error retry\n- TypeScript\n- React Suspense\n- React Native\n\n...and a lot more.\n\nWith SWR, components will get **a stream of data updates constantly and automatically**. Thus, the UI will be always **fast** and **reactive**.\n\n---\n\n**View full documentation and examples on [swr.vercel.app](https://swr.vercel.app).**\n\n\u003cbr/\u003e\n\n## Quick Start\n\n```js\nimport useSWR from 'swr'\n\nfunction Profile() {\n  const { data, error, isLoading } = useSWR('/api/user', fetcher)\n\n  if (error) return \u003cdiv\u003efailed to load\u003c/div\u003e\n  if (isLoading) return \u003cdiv\u003eloading...\u003c/div\u003e\n  return \u003cdiv\u003ehello {data.name}!\u003c/div\u003e\n}\n```\n\nIn this example, the React Hook `useSWR` accepts a `key` and a `fetcher` function.\nThe `key` is a unique identifier of the request, normally the URL of the API. And the `fetcher` accepts\n`key` as its parameter and returns the data asynchronously.\n\n`useSWR` also returns 3 values: `data`, `isLoading` and `error`. When the request (fetcher) is not yet finished,\n`data` will be `undefined` and `isLoading` will be `true`. When we get a response, it sets `data` and `error` based on the result\nof `fetcher`, `isLoading` to false and rerenders the component.\n\nNote that `fetcher` can be any asynchronous function, you can use your favourite data-fetching\nlibrary to handle that part.\n\n---\n\n**View full documentation and examples on [swr.vercel.app](https://swr.vercel.app).**\n\n\u003cbr/\u003e\n\n## Authors\n\nThis library is created by the team behind [Next.js](https://nextjs.org), with contributions from our community:\n\n- Shu Ding ([@shuding\\_](https://x.com/shuding_)) - [Vercel](https://vercel.com)\n- Jiachi Liu ([@huozhi](https://x.com/huozhi)) - [Vercel](https://vercel.com)\n- Guillermo Rauch ([@rauchg](https://x.com/rauchg)) - [Vercel](https://vercel.com)\n- Joe Haddad ([@timer150](https://x.com/timer150)) - [Vercel](https://vercel.com)\n- Paco Coursey ([@pacocoursey](https://x.com/pacocoursey)) - [Vercel](https://vercel.com)\n\n[Contributors](https://github.com/vercel/swr/graphs/contributors)\n\nThanks to Ryan Chen for providing the awesome `swr` npm package name!\n\n\u003cbr/\u003e\n\n## License\n\nThe MIT License.\n","funding_links":[],"categories":["Data Fetching","TypeScript","四、状态管理与数据获取","前端开发框架及项目","API","Frontend  frameworks \u0026 libraries","Frontend React","API [🔝](#readme)","Uncategorized","Component and Hook Libraries","React","vercel","目录","📖 Categories","Officially for Next.js","Thanks","Data Fetching \u0026 Networking"],"sub_categories":["2. 数据获取（异步状态）","其他_文本生成、文本对话","Runner","Utilities","Uncategorized","State Management","运行器","Hooks \u0026 Data Fetching","Data fetching","Vue 2","运行器e2e测试","\u003ca id=\"other\"\u003e其他\u003c/a\u003e","Graphics \u0026 Drawing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercel%2Fswr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvercel%2Fswr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercel%2Fswr/lists"}