From 6cb7d77bd43c38324aeefcfa389080efad7cbcc8 Mon Sep 17 00:00:00 2001 From: hyeseon han Date: Sat, 24 Feb 2024 00:47:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20useBaseInfiniteQuery=20parameter=20?= =?UTF-8?q?=EC=9A=94=EC=86=8C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81,=20ho?= =?UTF-8?q?ok=20=EB=B0=98=EC=98=81=20=EB=90=9C=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/queries/friendship/useGetFriendships.ts | 2 +- src/hooks/queries/useBaseInfiniteQuery.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hooks/queries/friendship/useGetFriendships.ts b/src/hooks/queries/friendship/useGetFriendships.ts index d3aa89e..deceb7d 100644 --- a/src/hooks/queries/friendship/useGetFriendships.ts +++ b/src/hooks/queries/friendship/useGetFriendships.ts @@ -7,7 +7,7 @@ const useGetFriendships = ({ sort }: { sort: FriendshipSortType }) => { return useBaseInfiniteQuery({ queryKey: queryKeys.FRIENDSHIPS(sort), url: '/friendship', - sort, + params: { sort }, }); }; diff --git a/src/hooks/queries/useBaseInfiniteQuery.ts b/src/hooks/queries/useBaseInfiniteQuery.ts index 6f9bf3d..7757855 100644 --- a/src/hooks/queries/useBaseInfiniteQuery.ts +++ b/src/hooks/queries/useBaseInfiniteQuery.ts @@ -13,12 +13,12 @@ export const useBaseInfiniteQuery = ({ queryKey, url, size, - sort, + params, }: { queryKey: QueryKey; url: string; size?: number; - sort?: string; + params?: Record; }) => { const INITIAL_PAGE_PARAM = 0; const DEFAULT_SIZE = 10; @@ -28,13 +28,14 @@ export const useBaseInfiniteQuery = ({ ) => { const { pageParam = 0 } = context; - const queryParamString = buildQuery({ + const paginationParamString = buildQuery({ page: pageParam, size: size ?? DEFAULT_SIZE, - sort, }); - const URL = `${url}?${queryParamString}`; + const queryParamString = params ? `&${buildQuery(params)}` : ''; + + const URL = `${url}?${paginationParamString}${queryParamString}`; const response = await axiosInstance.get>>(URL); return response.data.data;