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

Bug? If all items from initial batch fit to screen, loadMore is never triggered

Open baobabKoodaa opened this issue 5 years ago • 7 comments

I just started tinkering with this, so sorry if I've missed something, but at least with my current setup I have this issue: If all items from initial batch fit to screen, scrolling bar doesn't exist and loadMore is never triggered. If I resize the window smaller to make the window scrollable, loadMore is triggered again.

baobabKoodaa avatar Feb 26 '19 02:02 baobabKoodaa

Created PR for this: https://github.com/jaredpalmer/react-simple-infinite-scroll/pull/10

baobabKoodaa avatar Mar 05 '19 20:03 baobabKoodaa

I see your PR, but I'm still having this issue. Perhaps it's because of the conditional on threshold?

baleeds avatar Nov 13 '19 22:11 baleeds

Could you show a reproducible example of the issue? I could take a look tomorrow.

baobabKoodaa avatar Nov 13 '19 22:11 baobabKoodaa

Well, it was because the new version was never published to npm.

But there is another issue with your change, where I was getting duplicate keys. I was able to figure it out, it's because the function call in componentDidUpdate isn't using the throttled version of the scroll handler. But even with that fix, there's still issues with using componentDidMount in this case, I think because it's causing race conditions.

I wasn't sure how to get multiple loads other than to have onLoadMore return a promise and run checkWindowScroll on then.

Not sure what to do now though, since, Jared isn't publishing this package.

baleeds avatar Nov 14 '19 14:11 baleeds

Hmmh. Well, if you run out of ideas how to do it properly, one ugly way to do it would be to simply have a timer go off every 0.5 seconds or whatever and load more items if needed.

baobabKoodaa avatar Nov 14 '19 15:11 baobabKoodaa

I actually used a completely different solution, but I think it works well!

import React from 'react';
import InView from 'react-intersection-observer';

interface Props {
  onLoadMore?: () => void;
  loading?: boolean;
  hasNextPage?: boolean;
  offset?: number;
}

export const InfiniteScroll: React.FC<Props> = ({
  onLoadMore,
  loading,
  hasNextPage,
  offset = 1000,
}) => {
  const handleInView = (isInView: boolean) => {
    if (isInView && hasNextPage && !loading && onLoadMore) {
      onLoadMore();
    }
  };

  if (loading) return null;

  return (
    <InView rootMargin={`${offset}px`} onChange={handleInView}>
      {({ ref }) => <div ref={ref} />}
    </InView>
  );
};

baleeds avatar Nov 14 '19 15:11 baleeds

Hayho i was just debugging this till i realized:

Well, it was because the new version was never published to npm.

is still true :sweat_smile:

@jaredpalmer any chance of publishing a new version? :thinking:

sakulstra avatar Aug 07 '20 12:08 sakulstra