react-infinite-scroll-component icon indicating copy to clipboard operation
react-infinite-scroll-component copied to clipboard

next won't be triggered, if there is no scrollbar

Open overdoz opened this issue 3 years ago • 7 comments

Hey! When i zoom out and the entire list is displayed, there is no way of loading more data. I think this is because no scrollevent can be detected. Is there an out-of-the-box solution for this issue? Thanks!

overdoz avatar Aug 03 '21 16:08 overdoz

Got the same issue. I'm loading a list of rows but if the list does not overflow the window bottom edge it does not load any data.

image

<InfiniteScroll
    dataLength={data.transactions.transactions.length}
    next={() =>
      refetch({
          first: data.transactions.transactions.length + COUNT_TRANSACTIONS,
        })
    }
    hasMore={data.transactions.transactions.length < 100}
    loader={<SkeletonTransaction />}
    endMessage={
      <p style={{ textAlign: 'center' }}>
        <b>Yay! You have seen it all</b>
      </p>
    }
  >
    <TransactionList transactions={data.transactions.transactions} />
</InfiniteScroll>

cahbb avatar Aug 05 '21 11:08 cahbb

same problem

symbiosdotwiki avatar Aug 19 '21 21:08 symbiosdotwiki

i think at that case if your data container height is fixed you can set the height and scrollable target. but for many cases just increase the data limit until it reach more than window height

bryanprimus avatar Aug 21 '21 03:08 bryanprimus

As me, I triggered data fetch on first load like this:

 useEffect(() => {
      fetchMorePosts()
      // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [])

T-Damer avatar Aug 27 '21 08:08 T-Damer

Had this similar issue. Used a workaround for this problem by checking scrollbar visibility.

function scrollbarVisible(element) {
  return element.scrollHeight > element.clientHeight;
}

And then fetch next data on this condition. Hope it helps.

sourabkapoor avatar Sep 20 '21 17:09 sourabkapoor

@sourabkapoor and how did you get element?

victorsferreira avatar Apr 20 '22 03:04 victorsferreira

@victorsferreira You can use querySelector()/getElementById() to get your content div which is supposed to scroll.

sourabkapoor avatar Apr 20 '22 10:04 sourabkapoor