From 44fee96ca712978bb05eccad5911f0b68efa1879 Mon Sep 17 00:00:00 2001 From: jerry Date: Wed, 17 Jul 2024 00:18:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20useQuery=20=EC=98=88=EC=8B=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/domains/home/api.ts | 1 + src/apis/domains/home/queries.ts | 5 ++++- src/pages/main/Main.tsx | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/apis/domains/home/api.ts b/src/apis/domains/home/api.ts index 0bd45a54..7d9be603 100644 --- a/src/apis/domains/home/api.ts +++ b/src/apis/domains/home/api.ts @@ -5,6 +5,7 @@ import { AxiosResponse } from "axios"; type HomeResponse = components["schemas"]["HomeResponse"]; +// 1. API 요청 함수 작성 및 타입 추가 export const getAllScheduleList = async (): Promise => { try { const response: AxiosResponse> = await get("/main"); diff --git a/src/apis/domains/home/queries.ts b/src/apis/domains/home/queries.ts index 16d468f2..2699d32c 100644 --- a/src/apis/domains/home/queries.ts +++ b/src/apis/domains/home/queries.ts @@ -5,9 +5,12 @@ const QUERY_KEY = { LIST: "list", }; +// 2. 쿼리 작성 export const useGetAllScheduleList = () => { return useQuery({ queryKey: [QUERY_KEY.LIST], - queryFn: () => getAllScheduleList(), + queryFn: () => getAllScheduleList(), // API 요청 함수 + staleTime: 1000 * 60 * 60, + gcTime: 1000 * 60 * 60 * 24, }); }; diff --git a/src/pages/main/Main.tsx b/src/pages/main/Main.tsx index f7c73c4c..cc9cddb3 100644 --- a/src/pages/main/Main.tsx +++ b/src/pages/main/Main.tsx @@ -16,6 +16,7 @@ import { navigateAtom } from "@stores/navigate"; import { useAtom } from "jotai"; const Main = () => { + // 3. 훅 불러와서 사용 const { data, isLoading } = useGetAllScheduleList(); const [genre, setGenre] = useState("ALL");