Skip to content

Does scroll restoration work #677

Answered by KonstantinKai
L-Blondy asked this question in Q&A
Discussion options

You must be logged in to vote

Yep, just use the following options while creating an instance of virtualized

initialOffset: number;
initialMeasurementsCache: VirtualItem[],

Here is my snippet and it works fine for me:

let _kSavedOffset = 0;
let _KMeasurementsCache = [] as VirtualItem[];

const Element: React.FC = () => {
  const virtualized = useVIrtualizer({
    // options,
    initialOffset: _kSavedOffset,
    initialMeasurementsCache: _kMeasurementsCache,
    onChange: (virtualizer) => {
      if (!virtualizer.isScrolling) {
        _kMeasurementsCache = virtualizer.measurementsCache;
        _kSavedOffset = virtualizer.scrollOffset;
      }
    },
  });
  return <div>{/*your list goes here*/}</div>
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@younessbennaj
Comment options

@Frans06
Comment options

Answer selected by L-Blondy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants