{"id":14263200,"url":"https://github.com/TimMikeladze/use-octokit","last_synced_at":"2025-08-13T09:32:35.670Z","repository":{"id":195210972,"uuid":"692593141","full_name":"TimMikeladze/use-octokit","owner":"TimMikeladze","description":"A fully-typed data-fetching hook for the Github API. Built on top of Octokit and SWR. Use inside in a React component for a type-safe data-fetching mechanism over the Github API with caching, polling, and more.","archived":false,"fork":false,"pushed_at":"2024-10-30T02:45:41.000Z","size":225,"stargazers_count":5,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T05:10:26.735Z","etag":null,"topics":["github-api","github-hook","octokit","react-github","swr","use-github","use-octokit"],"latest_commit_sha":null,"homepage":"","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/TimMikeladze.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"ko_fi":"linesofcodedev","custom":["https://www.paypal.me/TimMikeladze"]}},"created_at":"2023-09-17T00:51:34.000Z","updated_at":"2024-09-18T08:42:30.000Z","dependencies_parsed_at":"2023-09-17T01:49:30.736Z","dependency_job_id":"dad84c5b-20bb-4722-b771-de36cfcfafb8","html_url":"https://github.com/TimMikeladze/use-octokit","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"abd6658c68fdceb6ba49ab8efd0f3a8233ac7903"},"previous_names":["timmikeladze/use-octokit"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fuse-octokit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fuse-octokit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fuse-octokit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fuse-octokit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimMikeladze","download_url":"https://codeload.github.com/TimMikeladze/use-octokit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229754507,"owners_count":18119127,"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":["github-api","github-hook","octokit","react-github","swr","use-github","use-octokit"],"created_at":"2024-08-22T13:03:09.140Z","updated_at":"2024-12-14T20:30:39.104Z","avatar_url":"https://github.com/TimMikeladze.png","language":"TypeScript","funding_links":["https://ko-fi.com/linesofcodedev","https://www.paypal.me/TimMikeladze"],"categories":["github-api"],"sub_categories":[],"readme":"# 🐙 use-octokit\n\nA fully-typed data-fetching hook for the Github API. Built on top of [Octokit](https://github.com/octokit/rest.js) and [SWR](https://swr.vercel.app/).\n\nUse this hook inside a React component for a type-safe, data-fetching experience with caching, polling, and more.\n\n\u003e 💡 Checkout an [example](https://github.com/TimMikeladze/use-octokit/blob/master/examples/nextjs) of `use-octokit` inside a [Next.js app](https://github.com/TimMikeladze/use-octokit/blob/master/examples/nextjs).\n\n## 📡 Install\n\n```console\nnpm install use-octokit\n\nyarn add use-octokit\n\npnpm add use-octokit\n```\n\n\u003e 👋 Hello there! Follow me [@linesofcode](https://twitter.com/linesofcode) or visit [linesofcode.dev](https://linesofcode.dev) for more cool projects like this one.\n\n## 🚀 Getting Started\n\nAfter you've obtained a github auth token, you can use the `useOctokit` hook to fetch data from the Github API.\n\nThe function inputs and outputs are all type-safe and the auto-complete in your IDE should kick-in to list all the available GitHub API endpoints and parameters.\n\nYou can also use the `OctokitProvider` to set the auth token for all the `useOctokit` calls in your app. It also accepts an octokit instance if you want to use your own.\n\nConditional fetching is supported by passing `undefined` as the first argument to `useOctokit` or by omitting the `auth` config.\n\nRemember this is an [SWR](https://swr.vercel.app/docs/getting-started) hook, so you can use all the [SWR config options](https://swr.vercel.app/docs/options) to customize the fetching behavior or nest it within your own SWR providers.\n\n**React hook example**\n\n```tsx\nimport { useOctokit } from 'use-octokit';\n\n// call the hook inside a React component\n\nconst user = useOctokit('users', 'getAuthenticated', undefined, {\n  auth: session.data?.user?.accessToken,\n});\n\n// The above is fully-typed SWR response object with the data, error and isLoading properties.\n// user.isLoading\n// user.data.avatar_url\n\nconst [page, setPage] = useState(0);\n\nconst repos = useOctokit(\n  'search',\n  'repos',\n  {\n    sort: 'updated',\n    q: 'nextjs',\n    page,\n  },\n  {\n    auth: session.data?.user?.accessToken,\n  },\n  {\n    refreshInterval: page === 0 ? 1000 * 10 : 0,\n  }\n);\n\n// The final argument is an optional SWR config object, in the example above the repos will be refetched every 10 seconds on the first page.\n// repos.isLoading\n// repos.data.items[0].full_name\n\nif (repos.isLoading || user.isLoading) {\n  return \u003cdiv\u003eLoading...\u003c/div\u003e;\n}\n```\n\n**React context provider example**\n\n```tsx\nimport { OctokitProvider } from 'use-octokit';\n\n// inside a React component render method\n\n// pass an auth token to the provider to use it for all the useOctokit calls in your app\nreturn (\n  \u003cOctokitProvider auth={session.data?.user?.accessToken}\u003e\n    {children}\n  \u003c/OctokitProvider\u003e\n);\n```\n\n\u003e 😅 Do you have problems consistently typing \"octokit\" without typos like I do? All the exports have a \"github\" alias, so you can use `useGithub` instead of `useOctokit` if you need.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTimMikeladze%2Fuse-octokit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTimMikeladze%2Fuse-octokit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTimMikeladze%2Fuse-octokit/lists"}