{"id":22315624,"url":"https://github.com/aprendendofelipe/next-swr","last_synced_at":"2025-10-01T17:30:47.841Z","repository":{"id":153269995,"uuid":"628130124","full_name":"aprendendofelipe/next-swr","owner":"aprendendofelipe","description":"Revalidate stale data in Next.js","archived":false,"fork":false,"pushed_at":"2024-07-16T17:03:23.000Z","size":809,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T19:00:14.550Z","etag":null,"topics":["cache","fetch","nextjs","request","revalidate","swr"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/next-swr","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/aprendendofelipe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-15T02:04:31.000Z","updated_at":"2024-01-17T19:20:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"d7b88c3a-7f93-472a-9541-0448f30dfa07","html_url":"https://github.com/aprendendofelipe/next-swr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprendendofelipe%2Fnext-swr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprendendofelipe%2Fnext-swr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprendendofelipe%2Fnext-swr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprendendofelipe%2Fnext-swr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aprendendofelipe","download_url":"https://codeload.github.com/aprendendofelipe/next-swr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234883314,"owners_count":18901366,"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","fetch","nextjs","request","revalidate","swr"],"created_at":"2024-12-03T22:22:52.504Z","updated_at":"2025-10-01T17:30:47.327Z","avatar_url":"https://github.com/aprendendofelipe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Revalidate stale data in Next.js\n\nInspired by [Vercel/swr](https://www.npmjs.com/package/swr), but no API needed, as it revalidates data through static pages.\n\nOnly one api call per session is needed to synchronize local and remote clocks. We recommend using the middleware.\n\n# Quickstart\n\n## Install\n\n```\n  npm install next-swr\n```\n\n## Usage\n\n```js\n// _app file\nimport { useRevalidate } from 'next-swr'\n\nfunction App({ Component, pageProps }) {\n  useRevalidate(pageProps) // Optional\n  return \u003cComponent {...pageProps} /\u003e\n}\n```\n\n```js\n// middleware\nimport { middlewareClock } from 'next-swr'\n\nexport const config = { matcher: ['/swr'] }\n\nexport const middleware = middlewareClock(async () = \u003e { ... });\n```\n\n```js\n// page files\nimport { getStaticPropsRevalidate, useRevalidate } from 'next-swr'\n\nfunction Page({ swr, ...props }) {\n  useRevalidate({ swr }) // Only if not in _app file\n  return \u003cComponent {...props} /\u003e\n}\n\nexport const getStaticProps = getStaticPropsRevalidate(async (ctx) =\u003e {\n  // get data...\n  return {\n    props: { data },\n    revalidate: 10\n  }\n)\n```\n\nIt is better to put `useRevalidate` only in the \\_app file as it reduces the number of renders and calls to the backend.\n\nIn this case, custom settings for each page can be returned via the swr object in getStaticProps.\n\n## Parameters\n\n- `swr`: an object of options for this hook\n\n### Examples\n\n```js\nfunction Page({ swr, ...props }) {\n  useRevalidate({ swr: {...swr, revalidateOnFocus: false } })\n```\n\nor\n\n```js\nexport const getStaticProps = getStaticPropsRevalidate(async () =\u003e {\n  // get data...\n  return {\n    props: { data },\n    swr: {\n      revalidate_f: 1,\n      refreshInterval: 30_000\n    }\n  }\n})\n```\n\n## Options\n\n- `revalidateIfStale = true`: automatically revalidate even if there is stale data\n- `revalidateOnMount = true`: enable or disable first automatic revalidation when component is mounted\n- `revalidateOnFocus = true`: automatically revalidate when window gets focused\n- `refreshInterval`:\n  - Disabled by default: `refreshInterval = 0`\n  - If set to a number, polling interval in milliseconds (min 50 ms)\n  - If set to a function, the function will receive the latest data and should return the interval in milliseconds\n- `dedupingInterval`: dedupe revalidate at least this time interval in milliseconds. Default is the elapsed time in the previous revalidation\n- `revalidate_f`: sets a fixed revalidate on `getStaticProps`. The default is automatic, being `revalidate` plus the elapsed time in the previous revalidation\n- `swrPath`: sets the endpoint to return the server time to synchronize expiration. Default is `/swr` which can be provided by `middlewareClock`\n\n## Incompatibility\n\nNot compatible with Next.js v13.3.0 due to a [bug.](https://github.com/vercel/next.js/issues/48302)\n\n## License\n\nThe MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faprendendofelipe%2Fnext-swr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faprendendofelipe%2Fnext-swr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faprendendofelipe%2Fnext-swr/lists"}