Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

handleInfiniteLoad() not called after 0 rendered elements #273

Open
PsyKoMari opened this issue Mar 23, 2018 · 3 comments
Open

handleInfiniteLoad() not called after 0 rendered elements #273

PsyKoMari opened this issue Mar 23, 2018 · 3 comments

Comments

@PsyKoMari
Copy link

I'm not sure if that's a issue btw I wanna report

I'm using this component to render ListItems containing folders data, so I use this to navigate between folders.
I request data from the server and build my ListItems with the functions handleInfiniteLoad() and buildElements() as examples shows.
All works perfectly except when I navigate in a empty folder...
The handleInfiniteLoad() is called, the buildElements() builds 0 items and ok, then I press "UP" to list previous folder, got data from the server, set the new state, but the list remains empty.

After some investigation I saw that I've to force call to handleInfiniteLoad() after it rendered 0 items to get it working again

<Infinite elementHeight={56}
    containerHeight={ 900 }
    infiniteLoadBeginEdgeOffset={this.state.infiniteLoadBeginEdgeOffsetMerish}
    onInfiniteLoad={ () => this.handleInfiniteLoad(true)}
    loadingSpinnerDelegate={ this.elementInfiniteLoad() }
    isInfiniteLoading={this.state.isMerishInfiniteLoading}
    timeScrollStateLastsForAfterUserScrolls={150}
    >
            {this.state.renderedElements}
</Infinite>
@geminiyellow
Copy link

yep, same issues, @garetht any idea?

@nodkrot
Copy link

nodkrot commented Sep 8, 2018

So annoying, it just renders the loader on scroll even though isInfiniteLoading=false and there is no more. Please fix!

@nodkrot
Copy link

nodkrot commented Sep 8, 2018

Actually all you need is this:

  componentDidMount() {
    window.addEventListener('scroll', this.onScroll, false)
    this.initialLoad()
  }

  componentWillUnmount() {
    window.removeEventListener('scroll', this.onScroll, false)
  }

  onScroll() {
    if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 300) {
      this.loadMore()
    }
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants