malte-wessel / react-custom-scrollbars

React scrollbars component
http://malte-wessel.github.io/react-custom-scrollbars/
MIT License
3.2k stars 577 forks source link

How to preventing scrolling to the bottom after new elements are inserting inside a list? #403

Open ntovr opened 2 years ago

ntovr commented 2 years ago

Hi everyone! In my case, I use onScrollFrame and wait until the user will scroll to the top of the list and after that, I make an async request to load more messages from the server (kinda lazy loading for supporting a massive amount of messages) but when I add new messages to the list (they are added to the top of the list), it scrolls to the bottom. How can I prevent it? I have an idea to calculate the difference between scroll heights using getScrollHeight before and after each loading but I hardly know where to begin. Do you have any ideas or is there any other way to go? Maybe some ready cases? I don't think I'm the first guy who is trying to do something like that. Thanks in advance.