question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadMore function never called

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
BrennonGcommented, Jul 15, 2018

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

2reactions
ZeroCool-85commented, May 23, 2019

I had the same problem, fixed by deleting ->

#root {
  overflow: auto;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

loadMore function never called · Issue #148 - GitHub
Hi, I cannot seem to get this to work at all, as the loadMore function never fires when reaching the end of the...
Read more >
angularjs - loadMore() is not being called on browser scroll in ...
The alert("called") is not being called on browser scroll. Can anyone help me where I am wrong or how can I achieve infinite...
Read more >
Load more does not work - WordPress.org
When I click on button Load more then new products are appeared on page but without title image and price. I see for...
Read more >
Not able to call "loadmoredata" function when scrolled to the ...
This question was dealing with the same issue. Basically you have to set a height on the datatable in order to use infinite...
Read more >
Load more functionality in ReactJS - Level Up Coding
I am not gonna show you how to set up a react project and the initial ... Create a load more button and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found