1- import { useRef , useEffect , useState } from 'react' ;
1+ import { useRef , useEffect , useMemo } from 'react' ;
22import { uuid } from '../utils' ;
33import { useRequestDebounce } from '.' ;
44
@@ -66,15 +66,19 @@ const useAsync = (props, tableManager) => {
6666 const {
6767 mode,
6868 config : { requestDebounceTimeout } ,
69- rowsApi : { rows } ,
69+ rowsApi : { rows, totalRows } ,
7070 paginationApi : { pageSize }
7171 } = tableManager ;
7272
7373 const asyncApi = useRef ( { } ) . current ;
7474 const rowsRequests = useRef ( [ ] ) ;
7575
7676 asyncApi . batchSize = props . batchSize ?? pageSize ;
77- asyncApi . isLoading = ! rowsRequests . current . length || ! rowsRequests . current . every ( request => rows [ request . from ] ) ;
77+ asyncApi . isLoading = useMemo ( ( ) => {
78+ if ( ! rowsRequests . current . length ) return true ;
79+ if ( totalRows === 0 ) return false ;
80+ if ( ! rowsRequests . current . every ( request => rows [ request . from ] ) ) return true ;
81+ } )
7882
7983 const onRowsRequest = async rowsRequest => {
8084 rowsRequests . current = [ ...rowsRequests . current , rowsRequest ] ;
@@ -92,7 +96,7 @@ const useAsync = (props, tableManager) => {
9296 const newRows = asyncApi . mergeRowsAt ( rows , result . rows , rowsRequest . from ) ;
9397 setRows ( newRows ) ;
9498 } ;
95- if ( result ?. totalRows ) setTotalRows ( result . totalRows ) ;
99+ if ( result ?. totalRows !== undefined ) setTotalRows ( result . totalRows ) ;
96100 } ;
97101
98102 const debouncedOnRowsRequest = useRequestDebounce ( onRowsRequest , requestDebounceTimeout ) ;
0 commit comments