Skip to content

Please tell me how to restore scrolling when using measureElement. #731

Answered by shunshimono
shunshimono asked this question in Q&A
Discussion options

You must be logged in to vote

@piecyk
Thank you. I was able to resolve it by saving measurementsCache to storage when leaving the page, and setting that value to initialMeasurementsCache when remounting.

Resumable code

"use client";

import { useWindowVirtualizer } from "@tanstack/react-virtual";
import { useRef, useEffect } from "react";
import Link from "next/link";

import { faker } from "@faker-js/faker";

const randomNumber = (min: number, max: number) =>
  faker.datatype.number({ min, max });

const sentences = new Array(100)
  .fill(true)
  .map(() => faker.lorem.sentence(randomNumber(20, 70)));

export default function Page() {
  const listRef = useRef<HTMLDivElement | null>(null);
  const virtualizer = useWin…

Replies: 1 comment 2 replies

Comment options

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

@shunshimono
Comment options

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