Skip to content

Instantly share code, notes, and snippets.

@yoavniran
Last active May 6, 2024 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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,
});
};
@blarfoon
Copy link

blarfoon commented Feb 3, 2019

How do I implement this in this example pretending it's a Grid component?

@ffjanhoeck
Copy link

Would be nice if you can provide an example.

@Cody0913
Copy link

Cody0913 commented Jun 7, 2019

https://codesandbox.io/s/eager-khorana-owt2y
Might not be too helpful, I ended up putting it inside of the InfiniteLoader component child function and got it working.

@brent-williams
Copy link

Thanks @Cody0913 was very useful

@naorye
Copy link

naorye commented Oct 29, 2019

@Cody0913 @yoavniran The type ListOnItemsRenderedProps requires also overscanStartIndex and overscanStopIndex which is missing in your implementation.

@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