Skip to content

Commit 9daa247

Browse files
committed
chore: 1 chunk ahead
1 parent 0818669 commit 9daa247

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/PaginatedTable/useScrollBasedChunks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ interface UseScrollBasedChunksProps {
1212
}
1313

1414
const THROTTLE_DELAY = 100;
15+
const CHUNKS_AHEAD_COUNT = 1;
1516

1617
export const useScrollBasedChunks = ({
1718
containerRef,
1819
totalItems,
1920
itemHeight,
2021
chunkSize,
2122
}: UseScrollBasedChunksProps): number[] => {
22-
const [activeChunks, setActiveChunks] = React.useState<number[]>([0]);
23+
const [activeChunks, setActiveChunks] = React.useState<number[]>(
24+
getArray(1 + CHUNKS_AHEAD_COUNT).map((index) => index),
25+
);
2326

2427
const calculateActiveChunks = React.useCallback(() => {
2528
const container = containerRef.current;
@@ -37,7 +40,7 @@ export const useScrollBasedChunks = ({
3740
const startChunk = Math.floor(visibleStartIndex / chunkSize);
3841
const endChunk = Math.floor(visibleEndIndex / chunkSize);
3942

40-
const newActiveChunks = getArray(endChunk - startChunk + 1).map(
43+
const newActiveChunks = getArray(endChunk - startChunk + 1 + CHUNKS_AHEAD_COUNT).map(
4144
(index) => startChunk + index,
4245
);
4346

0 commit comments

Comments
 (0)