clauderic / react-tiny-virtual-list

A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!
https://clauderic.github.io/react-tiny-virtual-list/
MIT License
2.46k stars 165 forks source link

Fix misuse of second argument as nextState (the actual argument is prevState) #27

Closed gabrielecirulli closed 7 years ago

gabrielecirulli commented 7 years ago

I am working on a horizontal timeline that uses react-tiny-virtual-list to reduce the amount of items rendered at any one time. Clicking on an item on this timeline should center it horizontally. I noticed that when clicking on an item after scrolling, the item would not center.

This fixes instances where, right after scrolling, a change in the scrollToIndex prop will not actually scroll to the item at the passed index correctly. This is due to the componentDidUpdate method considering the previous state to actually be the next state and looking at scrollChangeReason on it, seeing the old scrollChangeReason caused by the user scrolling, thus not calling scrollTo to actually center the element.

clauderic commented 7 years ago

Just published this change in 2.1.4, thanks again for your contribution 😄

gabrielecirulli commented 7 years ago

Perfect, thank you very much!