diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-24 14:52:04 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-24 19:12:06 +0100 |
| commit | 958569e09071e4bb290f0ec120b4309ae5983d2d (patch) | |
| tree | bb3e49a7b616ccf0acdef330294d7dbbb7339135 /src/services | |
| parent | 368fbbf83b913b90cef9dfbe4288e148d589d033 (diff) | |
refactor(project): replace repo api call method with hook and swr
Instead of using post slug and an environment variable to fetch repo
data, I use the given repo in each project MDX file. It allows me to
fetch data from another user/organization if needed.
To make it work, I no longer provide the full URL in MDX file. The new
format is: "User/repo-slug".
I also replaced the fetch method with SWR to improve caching and to
avoid React complaining about cleanup useEffect.
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/repos/github.ts | 15 |
1 files changed, 0 insertions, 15 deletions
diff --git a/src/services/repos/github.ts b/src/services/repos/github.ts deleted file mode 100644 index 37400ad..0000000 --- a/src/services/repos/github.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { RepoData } from '@ts/types/github'; - -/** - * Retrieve repository data from Github by slug. - * @param repo - The repository slug. - * @returns {Promise<RepoData>} - The repository data. - */ -export const getRepoData = async (repo: string): Promise<RepoData> => { - const user = process.env.NEXT_PUBLIC_GITHUB_USER; - const api = `https://api.github.com/repos/${user}/${repo}`; - - const response = await fetch(api); - - return response.json(); -}; |
