Skip to content

Instantly share code, notes, and snippets.

@yoavniran
Last active May 6, 2024 12:32
Show Gist options
  • Save yoavniran/9e2a8972a8586cba7d949f448ff002f3 to your computer and use it in GitHub Desktop.
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
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,
});
};
@willsmanley
Copy link

Great implementation @yoavniran @Cody0913 - this should be included in the default library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment