From ae8c042d9df8e65a31d67226f78c5981ea8cde86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20G=C3=B3mez?= Date: Sun, 10 Sep 2023 21:21:17 +0200 Subject: [PATCH] Refactor useRepos Hook --- src/hooks/useRepos.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hooks/useRepos.ts b/src/hooks/useRepos.ts index 22d634c..3bb8f1a 100644 --- a/src/hooks/useRepos.ts +++ b/src/hooks/useRepos.ts @@ -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(`/users/${githubUser}/repos`); return data; } export function useFetchRepositories(user: string) { - return useQuery(["repos", user], fetchRepos); + return useQuery({ + queryKey: ["repos", user], + queryFn: () => fetchRepos(user), + }); }