Skip to content

Commit

Permalink
Refactor useRepos Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sagomadev committed Sep 10, 2023
1 parent ed15de7 commit ae8c042
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/hooks/useRepos.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { QueryFunctionContext, useQuery } from "@tanstack/react-query";
import { useQuery } from "@tanstack/react-query";
import api from "../api/github";
import { Repository } from "./types";

async function fetchRepos(ctx: QueryFunctionContext) {
const [, githubUser] = ctx.queryKey;
async function fetchRepos(githubUser: string) {
const { data } = await api.get<Repository[]>(`/users/${githubUser}/repos`);
return data;
}

export function useFetchRepositories(user: string) {
return useQuery(["repos", user], fetchRepos);
return useQuery({
queryKey: ["repos", user],
queryFn: () => fetchRepos(user),
});
}

0 comments on commit ae8c042

Please sign in to comment.