Skip to content

Commit

Permalink
refactor: useBaseInfiniteQuery parameter 요소 리팩토링, hook 반영 된 부분 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeseon-han committed Feb 23, 2024
1 parent 023723c commit 6cb7d77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hooks/queries/friendship/useGetFriendships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const useGetFriendships = ({ sort }: { sort: FriendshipSortType }) => {
return useBaseInfiniteQuery<FriendshipData[]>({
queryKey: queryKeys.FRIENDSHIPS(sort),
url: '/friendship',
sort,
params: { sort },
});
};

Expand Down
11 changes: 6 additions & 5 deletions src/hooks/queries/useBaseInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const useBaseInfiniteQuery = <T>({
queryKey,
url,
size,
sort,
params,
}: {
queryKey: QueryKey;
url: string;
size?: number;
sort?: string;
params?: Record<string, any>;
}) => {
const INITIAL_PAGE_PARAM = 0;
const DEFAULT_SIZE = 10;
Expand All @@ -28,13 +28,14 @@ export const useBaseInfiniteQuery = <T>({
) => {
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<ApiResponseType<InfiniteQueryResult<T>>>(URL);
return response.data.data;
Expand Down

0 comments on commit 6cb7d77

Please sign in to comment.