@@ -2,8 +2,6 @@ import React from 'react';
22
33import { isEqual , throttle } from 'lodash' ;
44
5- import { getArray } from '../../utils' ;
6-
75interface UseScrollBasedChunksProps {
86 parentRef ?: React . RefObject < HTMLElement > ;
97 tableRef : React . RefObject < HTMLElement > ;
@@ -21,10 +19,8 @@ export const useScrollBasedChunks = ({
2119 totalItems,
2220 rowHeight,
2321 chunkSize,
24- } : UseScrollBasedChunksProps ) : number [ ] => {
25- const [ activeChunks , setActiveChunks ] = React . useState < number [ ] > (
26- getArray ( 1 + CHUNKS_AHEAD_COUNT ) . map ( ( index ) => index ) ,
27- ) ;
22+ } : UseScrollBasedChunksProps ) : boolean [ ] => {
23+ const [ activeChunks , setActiveChunks ] = React . useState < boolean [ ] > ( [ true , true ] ) ;
2824
2925 const calculateActiveChunks = React . useCallback ( ( ) => {
3026 const container = parentRef ?. current ;
@@ -40,12 +36,16 @@ export const useScrollBasedChunks = ({
4036 totalItems - 1 ,
4137 ) ;
4238
43- const startChunk = Math . floor ( visibleStartIndex / chunkSize ) ;
44- const endChunk = Math . floor ( visibleEndIndex / chunkSize ) ;
45-
46- const newActiveChunks = getArray ( endChunk - startChunk + 1 + CHUNKS_AHEAD_COUNT ) . map (
47- ( index ) => startChunk + index ,
39+ const startChunk = Math . max (
40+ Math . floor ( visibleStartIndex / chunkSize ) - CHUNKS_AHEAD_COUNT ,
41+ 0 ,
4842 ) ;
43+ const endChunk = Math . floor ( visibleEndIndex / chunkSize ) + CHUNKS_AHEAD_COUNT ;
44+
45+ const newActiveChunks = [ ] ;
46+ for ( let i = startChunk ; i <= endChunk ; i ++ ) {
47+ newActiveChunks [ i ] = true ;
48+ }
4949
5050 if ( ! isEqual ( activeChunks , newActiveChunks ) ) {
5151 setActiveChunks ( newActiveChunks ) ;
0 commit comments