How to use scrollToItem with InfiniteLoader?
See original GitHub issueHi,
I’m a little confused about how to call scrollToItem() when the VariableSizedList is within an InfiniteLoader tag. My understanding is that you would use createRef() to assign a new ref to the list, but there is already a ref getting passed down. I’ve tried running scrollToItem on this latter ref, but it doesn’t work:
return (
<InfiniteLoader
isItemLoaded={isItemLoaded}
itemCount={itemCount}
loadMoreItems={loadMoreItems}
>
{({ onItemsRendered, ref }) => {
if (scrollTargetBlockIndex>0) {
ref.current.scrollToItem(scrollTargetBlockIndex);
scrollToConsumerSuccess();
};
return (
<AutoSizer>
{
({height, width}) => (
<VariableSizeList
height={height}
width={width}
itemCount={consumerBlocks.length}
itemSize={getItemSize}
onItemsRendered={onItemsRendered}
ref={ref}
overscanCount={4}
minimumBatchSize={20}
>
{Row}
</VariableSizeList>
)
}
</AutoSizer>
)}}
</InfiniteLoader>
);
The key line is
ref.current.scrollToItem(scrollTargetBlockIndex);
How should I do this? Is it possible?
Thank you in advance.
Simon
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
Scroll to specific value - javascript - Stack Overflow
I'm using InfiniteLoader with FixedSizeGrid from bvaughn/react-window and I'm ... scrollToItem(20); }; <button className="ExampleButton" ...
Read more >Storing and Restoring Scroll Position with React Window
To restore the user to their previous scroll location, create a bit of state storing the user's most recent scroll location, then navigate ......
Read more >react-simple-infinite-loading v1 is out | Yvonnick Frin
import React from 'react'. import InfiniteLoading from 'react-simple-infinite-loading'. function Example({ items, fetchMore, hasMore }) {.
Read more >scrollToItem(at:at:animated:) | Apple Developer Documentation
scrollToItem (at:at:animated:) Scrolls the collection view contents until the specified item is visible. iOS 6.0+ iPadOS 6.0+ Mac Catalyst 13.0+ tvOS 9.0+ ...
Read more >react-window-infinite-loader examples - CodeSandbox
Learn how to use react-window-infinite-loader by viewing and forking react-window-infinite-loader example apps on CodeSandbox.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@manacoa I just dealt with something like this myself.
What worked for me was
key line being
virtualLoaderRef.current._listRef.scrollToItem(indexYouWantToScrollTo)
in conjunction with setting the ref onInfiniteLoader
Hope that’s helpful
It would be nice if
_listRef
was exposed publicly.@bvaughn had an alternative suggestion here: https://github.com/bvaughn/react-window/issues/324#issuecomment-528887341
His proposed solution doesn’t work for me, however, as it results in a whole bunch of typescript errors, so I’ll use
_listRef
for now.