Skip to content

I want to store scrollbar instance #447

Answered by idiotWu
blitzve0 asked this question in Q&A
Discussion options

You must be logged in to vote

Not familiar with react, but I don't think keeping a reference to the scrollbar instance will consume too much memory because the instance always exists unless you destroy the scrollbar via .destroy() method.

Regarding your code, as the scrollbar is constructed when router changes, I think we can simplify it as:

useLayoutEffect(() => {
  const scrollbar = Scrollbar.init(...);

  scrollbar.setPosition(0, 0); // you can use `.setPosition(0, 0)` instead of `.scrollTo(0, 0, 0)` to reset position

  return () => scrollbar.destroy(); // destroy it if necessary
}, [router]);

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@blitzve0
Comment options

@idiotWu
Comment options

@blitzve0
Comment options

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