0

I'm using the react-virtualized List within a functional component. It allows you to set a ref for the scorllable list div. I have an onScroll function that is currently capturing the scrollTop position of the scrolled list and storing it in fromPosition I also have a variable storing the toPosition I want to scroll to.

Does anyone have a clean way of enabling the List component to scroll from the fromPosition to the toPosition in a smooth animated way... and triggered when ever a certain piece of state changes (triggerVar)?

UCAudio
  • 77
  • 1
  • 5

1 Answers1

0

You can use the scrollTo method and achieve smooth scrolling by setting behavior to smooth.

listRef.current.scrollTo({ 
  top: toPosition, 
  behavior: 'smooth' 
})

You don't really need the fromPosition because scrollTo will scroll from the current position of the scroll.

CoodleNoodle
  • 324
  • 3
  • 17