react-infinite-scroller icon indicating copy to clipboard operation
react-infinite-scroller copied to clipboard

bug: changing hasMore before you scroll down doesnt update component

Open x3malmusic opened this issue 3 years ago • 1 comments

so today i had a problem and while i was reserching it, i discover that changing props doesnt update an infinite scroll component. Or it does update but event listeners are still there and they fire loadMore function when it shouldnt.

My situation is that i have two props, first one is total_count and other one is the count of actual items that i receive from the server. and my implementation of hasMore is looks something like:

hasMore = count < total_count

So on the first render i have 0 < 10 which is true and on the second render when server responded with items i have 10 < 10, which is false. So when i scroll down it invokes loadMore function despite the fact that hasMore is actually false. When i looked onto InfiniteScroll in react devtools, i found that hasMore prop is false. So that's definitely not the problem of my code.

x3malmusic avatar Jan 04 '22 15:01 x3malmusic

I have the same problem here, and I had to verify hasMore in loadMore like this:

const loadMore = () => {
    if (!isFetching && hasMore) {
      //....
    }
  };

This seems to work

yuujitaka avatar Jun 09 '22 19:06 yuujitaka