Skip to content

Commit

Permalink
refactor: 검색 무한 쿼리 Hooks 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
im-na0 committed Jul 12, 2024
1 parent 3ae63f7 commit 5a7b2c2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/hooks/api/useSearchQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useSuspenseInfiniteQuery } from "@tanstack/react-query";

import type { ISearchFilterInfo } from "@/types/searchFilterInfo";

import { fetchSearchList } from "@/apis/fetchSeachList";

export const useInfiniteSearchQuery = (searchInfo: ISearchFilterInfo) => {
const pageSize = 10;

return useSuspenseInfiniteQuery({
queryKey: [
"searchItems",
searchInfo.location,
searchInfo.checkIn,
searchInfo.checkOut,
searchInfo.quantityPeople,
searchInfo.sorted,
searchInfo.brunch,
searchInfo.pool,
searchInfo.oceanView,
],
queryFn: ({ pageParam = 0 }) =>
fetchSearchList(
searchInfo.location,
searchInfo.checkIn,
searchInfo.checkOut,
searchInfo.quantityPeople,
searchInfo.sorted,
searchInfo.brunch,
searchInfo.pool,
searchInfo.oceanView,
pageParam,
pageSize,
),
refetchOnMount: false,
refetchOnWindowFocus: false,
initialPageParam: 0,
getNextPageParam: (lastPage) => {
const lastData = lastPage?.content;
return lastData && lastData.length === pageSize
? lastPage?.number + 1
: undefined;
},
});
};

0 comments on commit 5a7b2c2

Please sign in to comment.