Skip to content

Commit 92a8cb1

Browse files
authored
Merge pull request #599 from formio/FIO-9671-fix-pagination
FIO-9671: fix Next pagination button
2 parents 74b0cd5 + 100e708 commit 92a8cb1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/hooks/usePagination.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,25 @@ export function usePagination<T>(
2424
const total: number | undefined = Array.isArray(dataOrFetchFunction)
2525
? dataOrFetchFunction.length
2626
: undefined;
27+
let serverCount: number | undefined;
2728

2829
const fetchPage = useCallback(
2930
async (page: number): Promise<void> => {
3031
const skip = (page - 1) * limit;
3132
let result;
3233
if (Array.isArray(dataOrFetchFunction)) {
3334
result = dataOrFetchFunction.slice(skip, skip + limit);
35+
serverCount = dataOrFetchFunction.length;
3436
setData(result);
3537
} else {
3638
result = await dataOrFetchFunction(limit, skip);
39+
serverCount = (result as any).serverCount;
3740
setData(result);
3841
}
39-
if (result.length < limit) {
40-
setHasMore(false);
42+
if (serverCount !== undefined) {
43+
setHasMore(page * limit < serverCount);
4144
} else {
42-
setHasMore(true);
45+
setHasMore(result.length >= limit);
4346
}
4447
},
4548
[limit, dataOrFetchFunction],

0 commit comments

Comments
 (0)