Coder Social home page Coder Social logo

Comments (9)

jgroh9 avatar jgroh9 commented on July 24, 2024 58

@infinitescrollissue @benistary I too had this same issue. In my case, the problem was related to the dataLength attribute. I had initially set it to the total count of all the records in the collection that I was trying to load, but it had to be set to the current length of the data being displayed. In the below example I originally had set dataLength={500} but this only called fetchMoreItems() once. After changing to dataLength={this.state.items.length} things started working as expected.

this.state = { items: [], hasMoreItems: true };

fetchMoreItems() {
  if (this.state.items.length >= 500) {
    this.setState({ hasMoreItems: false });
    return;
  }

  // a fake async api call
  setTimeout(() => {
    this.setState({
      items: this.state.items.concat(Array.from({ length: 20 }))
    });
  }, 500);
}

<InfiniteScroll
  dataLength={this.state.items.length}
  next={this.fetchMoreItems}
  hasMore={this.state.hasMoreItems}
>
</InfiniteScroll>

Hope this helps

from react-infinite-scroll-component.

Lesleytech avatar Lesleytech commented on July 24, 2024 6

@infinitescrollissue @benistary I too had this same issue. In my case, the problem was related to the dataLength attribute. I had initially set it to the total count of all the records in the collection that I was trying to load, but it had to be set to the current length of the data being displayed. In the below example I originally had set dataLength={500} but this only called fetchMoreItems() once. After changing to dataLength={this.state.items.length} things started working as expected.

this.state = { items: [], hasMoreItems: true };

fetchMoreItems() {
  if (this.state.items.length >= 500) {
    this.setState({ hasMoreItems: false });
    return;
  }

  // a fake async api call
  setTimeout(() => {
    this.setState({
      items: this.state.items.concat(Array.from({ length: 20 }))
    });
  }, 500);
}

<InfiniteScroll
  dataLength={this.state.items.length}
  next={this.fetchMoreItems}
  hasMore={this.state.hasMoreItems}
>
</InfiniteScroll>

Hope this helps

Thanks a million. This solved the problem

from react-infinite-scroll-component.

benistary avatar benistary commented on July 24, 2024 1

I have same problem. next prop calls fetchMoreData only when the array data has lenght 3 or more.

And yes I have scroll bar visible when page is initialised.

from react-infinite-scroll-component.

tommyalvarez avatar tommyalvarez commented on July 24, 2024

@infinitescrollissue did you set the prop more as true when fetching the first page of records? It's working for me. I have just implemented it

from react-infinite-scroll-component.

ankeetmaini avatar ankeetmaini commented on July 24, 2024

@infinitescrollissue in the first load of your data, make sure there's a scroll, in case your items are too less to cause a scroll the onScroll listener will not trigger.

from react-infinite-scroll-component.

nishalk01 avatar nishalk01 commented on July 24, 2024

Thanks that helped a lot

from react-infinite-scroll-component.

nilesh-jagtap-patona avatar nilesh-jagtap-patona commented on July 24, 2024

@infinitescrollissue @benistary I too had this same issue. In my case, the problem was related to the dataLength attribute. I had initially set it to the total count of all the records in the collection that I was trying to load, but it had to be set to the current length of the data being displayed. In the below example I originally had set dataLength={500} but this only called fetchMoreItems() once. After changing to dataLength={this.state.items.length} things started working as expected.

this.state = { items: [], hasMoreItems: true };

fetchMoreItems() {
  if (this.state.items.length >= 500) {
    this.setState({ hasMoreItems: false });
    return;
  }

  // a fake async api call
  setTimeout(() => {
    this.setState({
      items: this.state.items.concat(Array.from({ length: 20 }))
    });
  }, 500);
}

<InfiniteScroll
  dataLength={this.state.items.length}
  next={this.fetchMoreItems}
  hasMore={this.state.hasMoreItems}
>
</InfiniteScroll>

Hope this helps

Thanks a million. This solved the problem


Thats awesome, helped me a lot, this was the exact mistake I was doing ... Thanks a ton man

from react-infinite-scroll-component.

mertyldrr avatar mertyldrr commented on July 24, 2024

Thanks a lot, I was trying to understand where the problem is. A bit more explanatory text for dataLength would be good. It is hard to understand if it's total length of data or currently displayed data length (at least for me).

from react-infinite-scroll-component.

GokulSuresh27 avatar GokulSuresh27 commented on July 24, 2024

@infinitescrollissue @benistary I too had this same issue. In my case, the problem was related to the dataLength attribute. I had initially set it to the total count of all the records in the collection that I was trying to load, but it had to be set to the current length of the data being displayed. In the below example I originally had set dataLength={500} but this only called fetchMoreItems() once. After changing to dataLength={this.state.items.length} things started working as expected.

this.state = { items: [], hasMoreItems: true };

fetchMoreItems() {
  if (this.state.items.length >= 500) {
    this.setState({ hasMoreItems: false });
    return;
  }

  // a fake async api call
  setTimeout(() => {
    this.setState({
      items: this.state.items.concat(Array.from({ length: 20 }))
    });
  }, 500);
}

<InfiniteScroll
  dataLength={this.state.items.length}
  next={this.fetchMoreItems}
  hasMore={this.state.hasMoreItems}
>
</InfiniteScroll>

Hope this helps

Thanks a lott Man.

from react-infinite-scroll-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.