reactjsreact-virtualized

React virtualized list keep scroll position on window resize


I have a list of contacts. If the user scrolled down to "Simon" and then resized the window, the scroll position jumps to the top (equal to 0) and i want it to stay at the same position. I tryied saving the scroll position to the state using onScroll like this:

    this.savePosition(params.scrollTop);

and then on window resize event to read the position from the state and scroll to there like this:

    this.ref.current.scrollToPosition(this.state.scrollPosition);

but the problem is, the resize event causes onScroll to happen and onResize the state is always getting updated to 0 so my state is worth nothing. How can i get this to work?


Solution

  • Solved. Instead of scrolling to position via resize event, i do it via scrollTop like this: scrollTop={this.state.scrollPosition}