react-infinite-scroller
react-infinite-scroller copied to clipboard
bug: changing hasMore before you scroll down doesnt update component
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.
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