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

loadMore function never called

Open JustinMoser opened this issue 6 years ago • 10 comments

Hi, I cannot seem to get this to work at all, as the loadMore function never fires when reaching the end of the list of initial items.

My code as follows:

@inject('uiStore', 'journalStore', 'authStore', 'paperStore')
@observer
class SingleJournalPage extends Component {

  constructor(props){
    super(props);
    this.journalId = this.props.match.params.id;
    this.props.paperStore.setFilter((e) => parseInt(e.journalId, 10) === parseInt(this.journalId, 10));
    this.state = {
      hasMoreItems: true,
      articles: []
    }
    
    this.loadInitial();
  }

  loadInitial () {
    if (!this.props.paperStore.isLoading) {
      let journalId = this.journalId;
      this.props.paperStore.getPapersForJournal(journalId, 0, this._updateState, this);
    }
  }

  _updateState(component, filteredView, currentPage, totalPages){
    component.setState({
      articles: filteredView,
      hasMoreItems: currentPage < totalPages
    });
  }

  loadMore (page) {
    console.log("load more!");
    if(this.state.hasMoreItems){
      if (!this.props.paperStore.isLoading) {
        let journalId = this.journalId;
        this.props.paperStore.getPapersForJournal(journalId, page, this._updateState, this);
      }
    }
  }

  render () {

    var items = [];
    this.state.articles.map((element, index) => {
      items.push(
        <div key={index}>
          <PaperComponent key={index} data={element}/>
          <hr/>
        </div>
      )
    })

    const journal = this.props.journalStore.data.get(this.journalId);
    return (
      <div className="SingleJournalPage">
        <BackButton/>
        <h2>{journal && journal.name}</h2>
        <ReactPlaceholder type='media' rows={10}
          style={{marginTop: '5em'}}
          ready={!this.props.paperStore.isLoading}
          showLoadingAnimation={true}>
          <div></div>
        </ReactPlaceholder>

        <InfiniteScroll
              pageStart={0}
              loadMore={this.loadMore.bind(this)}
              hasMore={this.state.hasMoreItems && !this.props.paperStore.isLoading}
              loader={<div className="loader" key={0}>Loading ...</div>}>
              <div className="SingleJournalWrapper">
                {items}
                <ReactPlaceholder type='media' rows={10}
                  style={{marginTop: '5em'}}
                  ready={!this.props.paperStore.isLoading}
                  showLoadingAnimation={true}>
                  <div></div>
                </ReactPlaceholder>
                <ReactPlaceholder type='media' rows={10}
                  ready={!this.props.paperStore.isLoading}
                  showLoadingAnimation={true}>
                  <div></div>
                </ReactPlaceholder>
                <ReactPlaceholder type='media' rows={10} 
                  ready={!this.props.paperStore.isLoading}>
                  <div></div>
                </ReactPlaceholder>
              </div>
        </InfiniteScroll>
      </div>
    );
  };
}

The loadMore function just never seems to fire at all. I have even tried just replacing my call to this.loadMore.bind(this) with {(e) => console.log("load more: ", e)} and still nothing.

Thanks, Justin

JustinMoser avatar Apr 16 '18 10:04 JustinMoser

+1 I am seeing the same

nodediggity avatar Apr 20 '18 08:04 nodediggity

Hi, sorry you're experiencing problems. Can you see if my comment about CSS on issue https://github.com/CassetteRocks/react-infinite-scroller/issues/14#issuecomment-310931311 is the solution

danbovey avatar Apr 20 '18 09:04 danbovey

I recently updated the issue templates on this repo so that I can identify the bugs with this repo.

Please clone your layout and use of react-infinite-scroller by forking this Code Sandbox and linking it here. Doing so will massively expedite getting the bug fixed! 👊

danbovey avatar May 14 '18 19:05 danbovey

Did you try set useWindow to false?

olga-giza avatar Jul 13 '18 14:07 olga-giza

I've got the same issue - can't get loadMore() to fire when scrolling down page, and have tried the solutions mentioned above. Can't figure out what I'm missing here.

I've pulled my data-fetching out of loadMore() - just trying to get it to fire... scratching my head...

screen shot 2018-07-13 at 4 42 29 pm

---UPDATE---- ----okay - adding a solution that is working for me--- In general, the loadMore() function wasn't connecting or firing w/ scroll event listener - still not sure why. So I manually added the scroll event listener in componentDidMount, and then defined scroll-point at which I wanna grab more data. Seems to be working. screen shot 2018-07-14 at 8 22 49 pm

BrennonG avatar Jul 13 '18 20:07 BrennonG

I'm having the same issue, but @BrennonG, any reason you're starting to load your data at page 20?

jameyel avatar Jul 14 '18 00:07 jameyel

No, @jameyel, was just toggling everything in the off chance something had an unexpected effect - shoulda put it at zero for the screenshot above

BrennonG avatar Jul 14 '18 02:07 BrennonG

Did you try set useWindow to false?

@olga-giza this fixed the issue for me!

dst3p avatar Jan 08 '19 17:01 dst3p

I had the same problem, fixed by deleting ->

#root {
  overflow: auto;
}

ZeroCool-85 avatar May 23 '19 13:05 ZeroCool-85

I also had the same problem, @ZeroCool-85 comment fixed it for me.

Danielshow avatar Mar 15 '21 18:03 Danielshow