bvaughn / react-window

React components for efficiently rendering large lists and tabular data
https://react-window.now.sh/
MIT License
15.48k stars 778 forks source link

Need access to current scroll offset to avoid two lists scrolling each other exceed maximum rerender depth. #745

Closed TomasPlachy closed 8 months ago

TomasPlachy commented 8 months ago

I need two lists to scroll together (a.g. scrolling one will scroll the other as well and vice versa). But using <FirstList onScroll={({scrollOffset})=> secondListRef.scrollTo(scrollOffset)} .../>
and <SecondList onScroll={({scrollOffset})=>firstListRef.scrollTo(scrollOffset)} .../>
creates infinite scroll updates and the app crashes by reaching maximum rerender depth.

Could you include a way to access the current offset of component so that it can be used to block further calling of scrollTo (when both offsets are the same). Of course I can store the offsets in state variables but that is too slow and causes laggy scrolling, only viable scrolling is by using refrences.

Or do you have any thoughts how to implement this behaviour?

P.S.: In reality I want VariableSizeGrid as a table with variable widths of columns but fixed heights of rows and FixedSizeList as first column (headers of rows) to scroll together in Y direction, but I simplyfied it in the example above);

TomasPlachy commented 8 months ago

Found out that the scrollUpdateWasRequested passed to onScroll function solves this issue.