ankeetmaini / react-infinite-scroll-component

An awesome Infinite Scroll component in react.
https://react-infinite-scroll-component.netlify.com/
MIT License
2.87k stars 322 forks source link

Inverse scroller - loader is not visible on top #322

Open aviram-s opened 2 years ago

aviram-s commented 2 years ago

When scrolling up (Inverse) to the top, I expect to see the loader component on top of the page until new data is loaded. Instead, the scroller is adding the loader component as a new item at the top, but the scroller stays at the same position so the user needs to scroll up a touch to see the loader component. Any ideas how to fix it? Code (based on duke7able example): https://codesandbox.io/s/youthful-kapitsa-nlv1j (increase setTimeout)

image

aviram-s commented 2 years ago

Manage to work around this issue although I'm sure there are better ways to do it:

  1. Make a ref object and assign it to the scroller container div.
  2. pass the ref object to the loader component.
  3. useEffect/component is mounted and set the scrollTop to the scrollHeight * -1:
  4. scrollerContainer.current.scrollTop = scrollerContainer.current.scrollHeight * -1

I'm leaving this issue open incase there are better solutions