aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-github-api.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-06 18:20:54 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-07 19:12:11 +0100
commitb8eb008dd5927fb736e56699637f5f8549965eae (patch)
tree648274babea3d3d09ed3e0f5f1fef013f94158fb /src/utils/hooks/use-github-api.tsx
parent802285872a2c57e7a5e130f32a2b45497d7687f1 (diff)
refactor(hooks): replace useGithubApi with useGithubRepoMeta
* use GraphQL API instead of REST (the inconvenient however is that we now need an authorization token...) * move fetcher in services * add tests * mock response using MSW
Diffstat (limited to 'src/utils/hooks/use-github-api.tsx')
-rw-r--r--src/utils/hooks/use-github-api.tsx28
1 files changed, 0 insertions, 28 deletions
diff --git a/src/utils/hooks/use-github-api.tsx b/src/utils/hooks/use-github-api.tsx
deleted file mode 100644
index aa9e3f7..0000000
--- a/src/utils/hooks/use-github-api.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import useSWR, { Fetcher } from 'swr';
-import { SWRResult } from '../../types';
-
-export type RepoData = {
- created_at: string;
- updated_at: string;
- stargazers_count: number;
-};
-
-const fetcher: Fetcher<RepoData, string> = (...args) =>
- fetch(...args).then((res) => res.json());
-
-/**
- * Retrieve data from Github API.
- *
- * @param repo - The Github repo (`owner/repo-name`).
- * @returns The repository data.
- */
-export const useGithubApi = (repo: string): SWRResult<RepoData> => {
- const apiUrl = repo ? `https://api.github.com/repos/${repo}` : null;
- const { data, error } = useSWR<RepoData>(apiUrl, fetcher);
-
- return {
- data,
- isLoading: !error && !data,
- isError: error,
- };
-};