petyosi / react-virtuoso

The most powerful virtual list component for React
https://virtuoso.dev
MIT License
5.16k stars 299 forks source link

preserve scrollLeft position? #1002

Closed esmalleydev closed 10 months ago

esmalleydev commented 10 months ago

Is it possible to preserve or set an initial scroll left? similar to scroll top?

I have a table, with sortable headers, when I scroll left, sort by a header, the table resets scrollLeft to 0.

My current fix is to use scrollerRef, keep track of horizontal scroll in the state, the scroll element and with a useEffect to set the ref.current.scrollLeft. However this is reset by another render, so I need a 0ms setTimeout to set it at the end of execution. This causing an annoying flash.

petyosi commented 10 months ago

No, there is no such utility.