Is it possible to cancel virtualizer's scrollToIndex? #1128
Unanswered
kristalshards
asked this question in
General
Replies: 1 comment
-
|
Right now, scrollToIndex doesn’t expose a cancellation mechanism. Internally it schedules scroll work (e.g. via requestAnimationFrame for dynamic lists or smooth behavior), and if the scroll element is removed before that runs, it can blow up as you observed. That’s something we should fix on our side, if there’s no scroll container anymore, the scroll should simply be a no-op rather than throwing. Also worth noting: you can always implement your own “scroll to index” on top of the virtualizer (compute the offset and call scrollTo directly), which gives you full control over cancellation/guards if you need it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have encountered a situation which is as follows:
A component (let's call it Table) that is rendered receives a
loadingprop. If this prop is true, it returns early by rendering an indicator. If not, I am rendering a bunch of stuff, including a Container which has a ref callback attached to it and that is sent touseVirtualizer()getScrollElementand its children is another component that maps overvirtualizer.getVirtualItems(). So in other words:Upon clicking a toggle, I want to scroll to a specific index (using scrollToIndex function provided by virtualizer). Now the problem is this:
TypeError: Cannot read properties of null (reading 'requestAnimationFrame')=> coming from this:My question, is it possible to cancel this scrollToIndex function once it's initiated? Or how can I think as a mental model to fix this issue?
Beta Was this translation helpful? Give feedback.
All reactions