Skip to content

Commit c1cefbf

Browse files
committed
add ability to control more data
1 parent 908aed4 commit c1cefbf

File tree

5 files changed

+283
-247
lines changed

5 files changed

+283
-247
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## 1.5.1
4+
5+
_2025-06-16_
6+
7+
### Bugfix
8+
9+
- added `hasMoreData` so users can have more control over when loading needs to occur
10+
311
## 1.5.0
412

513
_2025-06-11_

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ export type TableProps<T> = {
341341
* we have exhausted all remaining data.
342342
*/
343343
onLoadRows?: () => Promise<boolean>;
344+
/**
345+
* boolean to determine if there is more data to be loaded. If omitted, then the
346+
* result of `onLoadRows` determines this.
347+
*/
348+
hasMoreData?: boolean;
344349
/**
345350
* Number of rows from the bottom to trigger loading more rows. This is ignored if
346351
* onLoadRows is not specified (default: 1).

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fluid-table",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "A React table inspired by @tanstack/react-virtual",
55
"author": "Mckervin Ceme <mckervinc@live.com>",
66
"license": "MIT",
@@ -62,44 +62,44 @@
6262
"@babel/preset-env": "^7.27.2",
6363
"@babel/preset-react": "^7.27.1",
6464
"@babel/preset-typescript": "^7.27.1",
65-
"@eslint/compat": "^1.2.9",
65+
"@eslint/compat": "^1.3.0",
6666
"@eslint/eslintrc": "^3.3.1",
67-
"@eslint/js": "^9.28.0",
67+
"@eslint/js": "^9.29.0",
6868
"@rollup/plugin-babel": "^6.0.4",
69-
"@rollup/plugin-commonjs": "^28.0.3",
69+
"@rollup/plugin-commonjs": "^28.0.5",
7070
"@rollup/plugin-node-resolve": "^16.0.1",
7171
"@rollup/plugin-terser": "^0.4.4",
7272
"@rollup/plugin-url": "^8.0.2",
7373
"@svgr/rollup": "^8.1.0",
7474
"@testing-library/react-hooks": "^8.0.1",
7575
"@types/react": "^19",
76-
"@typescript-eslint/eslint-plugin": "^8.34.0",
77-
"@typescript-eslint/parser": "^8.34.0",
76+
"@typescript-eslint/eslint-plugin": "^8.34.01",
77+
"@typescript-eslint/parser": "^8.34.01",
7878
"concurrently": "^9.1.2",
7979
"cross-env": "^7.0.3",
80-
"eslint": "9.28.0",
80+
"eslint": "9.29.0",
8181
"eslint-config-prettier": "^10.1.5",
8282
"eslint-plugin-prettier": "^5.4.1",
8383
"eslint-plugin-react-hooks": "^5.2.0",
8484
"eslint-plugin-react-refresh": "^0.4.20",
8585
"gh-pages": "^6.3.0",
8686
"globals": "^16.2.0",
87-
"postcss": "^8.5.4",
87+
"postcss": "^8.5.6",
8888
"prettier": "^3.5.3",
8989
"react": "^19.1.0",
9090
"rimraf": "^6.0.1",
91-
"rollup": "^4.42.0",
91+
"rollup": "^4.43.0",
9292
"rollup-plugin-analyzer": "^4.0.0",
9393
"rollup-plugin-bundle-size": "^1.0.3",
9494
"rollup-plugin-peer-deps-external": "^2.2.4",
9595
"rollup-plugin-postcss": "^4.0.2",
9696
"rollup-plugin-visualizer": "^6.0.3",
9797
"typescript": "^5.8.3",
98-
"typescript-eslint": "^8.34.0"
98+
"typescript-eslint": "^8.34.01"
9999
},
100100
"dependencies": {
101101
"@tanstack/react-virtual": "^3.13.10",
102-
"react-resize-detector": "^12.0.2"
102+
"react-resize-detector": "^12.1.0"
103103
},
104104
"volta": {
105105
"node": "20.12.1",

src/components/List.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function BaseList<T>(
7070
maxTableHeight,
7171
estimatedRowHeight,
7272
style = {},
73+
hasMoreData: controlledHasMoreData,
7374
asyncOverscan = 1,
7475
minColumnWidth = 80,
7576
endComponent: EndComponent,
@@ -85,7 +86,7 @@ function BaseList<T>(
8586
const footerRef = useRef<HTMLDivElement>(null);
8687
const [loadingMore, setLoadingMore] = useState(false);
8788
const prevRowHeight = useRef(rowHeight ?? estimatedRowHeight);
88-
const [hasMoreData, setHasMoreData] = useState(true);
89+
const [hasMoreData, setHasMoreData] = useState(controlledHasMoreData ?? true);
8990
const [widthConstants, setWidthConstants] = useState(findColumnWidthConstants(columns));
9091
const [pixelWidths, setPixelWidths] = useState<number[]>(() => {
9192
const { fixedWidth, remainingCols } = widthConstants;
@@ -105,6 +106,7 @@ function BaseList<T>(
105106

106107
// constants
107108
const items = virtualizer.getVirtualItems();
109+
const hasNextPage = controlledHasMoreData ?? hasMoreData;
108110
const { measure: recalculate, measurementsCache } = virtualizer;
109111
const { fixedWidth, remainingCols } = widthConstants;
110112

@@ -176,17 +178,19 @@ function BaseList<T>(
176178
return;
177179
}
178180

179-
if (hasMoreData && lastItemIndex >= data.length - asyncOverscan && !loadingMore) {
181+
if (hasNextPage && lastItemIndex >= data.length - asyncOverscan && !loadingMore) {
180182
setLoadingMore(true);
181183
try {
182184
const remainingData = await onLoadRows();
183-
setHasMoreData(remainingData);
185+
if (controlledHasMoreData == null) {
186+
setHasMoreData(remainingData);
187+
}
184188
} finally {
185189
setLoadingMore(false);
186190
}
187191
}
188192
// eslint-disable-next-line react-hooks/exhaustive-deps
189-
}, [lastItemIndex, data.length, loadingMore, asyncOverscan, hasMoreData]);
193+
}, [lastItemIndex, data.length, loadingMore, asyncOverscan, hasNextPage, controlledHasMoreData]);
190194

191195
// effects
192196
// update pixel widths every time the width changes
@@ -268,7 +272,7 @@ function BaseList<T>(
268272
data-row-key={key}
269273
style={{ transform: `translateY(${start}px)` }}
270274
>
271-
<EndComponent isLoading={loadingMore} hasMoreData={hasMoreData} />
275+
<EndComponent isLoading={loadingMore} hasMoreData={hasNextPage} />
272276
</div>
273277
);
274278
}

0 commit comments

Comments
 (0)