Does scroll restoration work #677
-
Hi there, I'm considering using tanstack virtual at work and scroll restoration is a requirement. Does it work properly when navigating back / forward? I could not find anything about it in the docs. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
KonstantinKai
Apr 16, 2024
Replies: 1 comment 2 replies
-
Yep, just use the following options while creating an instance of 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>
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
L-Blondy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, just use the following options while creating an instance of
virtualized
Here is my snippet and it works fine for me: