Skip to content

Commit d364d5e

Browse files
committed
fixed issue where the loader is displayed instead of "no results" in async flows.
1 parent de7d3ec commit d364d5e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/hooks/useAsync.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useEffect, useState } from 'react';
1+
import { useRef, useEffect, useMemo } from 'react';
22
import { uuid } from '../utils';
33
import { 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);

src/hooks/useRows.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const useRows = (props, tableManager) => {
55

66
const rowsApi = useRef({}).current;
77
let [rows, setRows] = useState([]);
8-
const [totalRows, setTotalRows] = useState(0);
8+
const [totalRows, setTotalRows] = useState(null);
99

1010
Object.defineProperty(rowsApi, "onRowClick", { enumerable: false, writable: true });
1111

0 commit comments

Comments
 (0)