Skip to content

Commit c7b06af

Browse files
fix: getNextPageParam 실행 조건 수정
1 parent 17cf360 commit c7b06af

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

apps/client/src/pages/jobPins/apis/queries.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {
66
JobPinsDetailResponse,
77
} from './axios';
88

9+
const PAGE_SIZE = 20;
10+
911
export const useGetJobPinsArticles = () => {
1012
return useInfiniteQuery<JobPinsResponse>({
1113
queryKey: ['jobPinsArticles'],
1214
queryFn: ({ pageParam = 0 }) => getJobPinsArticles(pageParam as number, 20),
1315
initialPageParam: 0,
1416
getNextPageParam: (lastPage, allPages) => {
15-
if (lastPage.articles.length === 0) {
17+
if (lastPage.articles.length < PAGE_SIZE) {
1618
return undefined;
1719
}
1820

apps/client/src/pages/myBookmark/apis/queries.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import {
33
useSuspenseInfiniteQuery,
44
useSuspenseQuery,
55
} from '@tanstack/react-query';
6+
import { CategoryBookmarkArticleResponse } from '../types/api';
67
import {
78
getBookmarkArticles,
89
getBookmarkArticlesCount,
910
getCategoryBookmarkArticles,
1011
getCategoryBookmarkArticlesCount,
1112
} from './axios';
12-
import {
13-
CategoryBookmarkArticleResponse,
14-
} from '../types/api';
13+
14+
const PAGE_SIZE = 20;
1515

1616
export const useGetBookmarkArticles = (readStatus: boolean | null) => {
1717
return useSuspenseInfiniteQuery({
@@ -20,7 +20,7 @@ export const useGetBookmarkArticles = (readStatus: boolean | null) => {
2020
getBookmarkArticles(readStatus, Number(pageParam), 20),
2121
initialPageParam: 0,
2222
getNextPageParam: (lastPage, allPages) =>
23-
lastPage.articles.length === 0 ? undefined : allPages.length,
23+
lastPage.articles.length < PAGE_SIZE ? undefined : allPages.length,
2424
});
2525
};
2626

@@ -55,7 +55,8 @@ export const useGetCategoryBookmarkArticles = (
5555

5656
initialPageParam: 0,
5757
getNextPageParam: (lastPage, allPages) => {
58-
if (!lastPage || lastPage.articles.length === 0) return undefined;
58+
if (!lastPage) return undefined;
59+
return lastPage.articles.length < PAGE_SIZE ? undefined : allPages.length;
5960
return allPages.length;
6061
},
6162
});

0 commit comments

Comments
 (0)