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

Changing the hasMore prop without loading data will not change the component

Open danielittlewood0 opened this issue 3 years ago • 1 comments

Hi, thanks for maintaining this project - it has allowed us to consider implementing infinite scroll when we would not have otherwise :smile:

I'm having some trouble. In our app, the definition of "reaching the end of the feed" is "making a request which returns an empty payload". We don't have a special param which indicates that the last page was served. Therefore, we make a request, find no data, change the "hasMore" prop to "false" and leave the dataLength as it was.

Unfortunately, in this circumstance the component will not reload. This leaves us with loading bubbles at the bottom of the feed. I believe the responsible code from index.tsx is below:

  componentDidUpdate(prevProps: Props) {
    // do nothing when dataLength is unchanged
    if (this.props.dataLength === prevProps.dataLength) return;

    this.actionTriggered = false;

    // update state when new data was sent in
    this.setState({
      showLoader: false,
    });
  }

It feels like the check ought to be "this.props === prevProps", but maybe this causes issues with props like "next". Perhaps instead "hasMore" should be included in the list of "refreshable props"?

danielittlewood0 avatar Jan 18 '22 14:01 danielittlewood0

Please watch this video for this library https://youtu.be/c0nKjMnDfG4

subu873 avatar May 30 '22 11:05 subu873