File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff 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 ] ,
You can’t perform that action at this time.
0 commit comments