Skip to content

Commit

Permalink
feat: useQuery 예시 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pepperdad committed Jul 16, 2024
1 parent 2c55da9 commit 44fee96
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apis/domains/home/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AxiosResponse } from "axios";

type HomeResponse = components["schemas"]["HomeResponse"];

// 1. API 요청 함수 작성 및 타입 추가
export const getAllScheduleList = async (): Promise<HomeResponse | null> => {
try {
const response: AxiosResponse<ApiResponseType<HomeResponse>> = await get("/main");
Expand Down
5 changes: 4 additions & 1 deletion src/apis/domains/home/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};
1 change: 1 addition & 0 deletions src/pages/main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 44fee96

Please sign in to comment.