Skip to content

Commit

Permalink
feat: 페이지 크기 이하일 경우 추가 투표 목록 불러오기 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
mintmin0320 committed Apr 3, 2024
1 parent 7f80624 commit c414a46
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/app/_hook/api/votes/useVoteListData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ interface VoteQueryParams {
sortOption: string
}

const VOTE_FETCH_SIZE = 6

async function fetchVoteData({
pageParam,
hobby,
sortOption,
}: VoteQueryParams) {
const SIZE = 6
let URL = `${process.env.NEXT_PUBLIC_BASE_URL}/api/votes?hobby=${hobby}&size=${SIZE}&sort=${sortOption}`
let URL = `${process.env.NEXT_PUBLIC_BASE_URL}/api/votes?hobby=${hobby}&size=${VOTE_FETCH_SIZE}&sort=${sortOption}`

if (pageParam) {
URL += `&cursorId=${pageParam}`
Expand Down Expand Up @@ -46,6 +47,10 @@ export const useVoteListData = (hobby: string, sortOption: string) => {
fetchVoteData({ pageParam, sortOption, hobby }),
initialPageParam: null,
getNextPageParam: (lastPage: PagesResponse) => {
if (lastPage.totalCount < VOTE_FETCH_SIZE) {
return null
}

return lastPage.nextCursorId
},
staleTime: 1000 * 60,
Expand Down

0 comments on commit c414a46

Please sign in to comment.