Last active
May 6, 2024 12:32
-
-
Save yoavniran/9e2a8972a8586cba7d949f448ff002f3 to your computer and use it in GitHub Desktop.
convert data from react-window Grid's onItemsRendered to data that react-window-infinite-loader's onItemsRendered understands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onItemsRendered = (gridData: Object) => { | |
const {useOverscanForLoading} = this.props; //default is true | |
const { | |
visibleRowStartIndex, | |
visibleRowStopIndex, | |
visibleColumnStopIndex, | |
overscanRowStartIndex, | |
overscanRowStopIndex, | |
overscanColumnStopIndex | |
} = gridData; | |
const endCol = | |
(useOverscanForLoading ? overscanColumnStopIndex : visibleColumnStopIndex) + 1; | |
const startRow = (useOverscanForLoading ? overscanRowStartIndex : visibleRowStartIndex); | |
const endRow = (useOverscanForLoading ? overscanRowStopIndex : visibleRowStopIndex); | |
const visibleStartIndex = startRow * endCol; | |
const visibleStopIndex = endRow * endCol; | |
this.props.onItemsRendered({ //call onItemsRendered from InfiniteLoader so it can load more if needed | |
visibleStartIndex, | |
visibleStopIndex, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Cody0913 @yoavniran The type ListOnItemsRenderedProps requires also overscanStartIndex and overscanStopIndex which is missing in your implementation.