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.

Must InfiniteLoader's loadMoreRows use promises?

See original GitHub issue

The InfiniteLoader List example says to add at least 1 to the rowCount if there’s more to load. This is needed for it to trigger the loading. Unfortunately, it also causes the list to attempt to render a row even though the data is not there. Then, once the data shows up, that row does not get re-rendered until much later, when you stop scrolling with that row in view. This leaves a noticeable gap in your list.

Here’s my repro case. Keep scrolling steadily without stopping and you’ll notice that the numbers 20 and 21 do not show up unless you let your scrolling hit a dead stop. Ditto for 40 and 41. This is because I’m loading items in chunks of 20 and adding 2 rows of buffer.

I tried a bunch of workarounds for this:

  • I tried making isRowLoaded return true or false for this row, but it made no difference.
  • I tried simply not returning a value from renderRow, but that caused my scroll position to jump back to the top of the document when I reached it.
  • I tried passing a rowCount that includes the extra row to the <InfiniteLoader> and a rowCount that does not include the extra row to the <List>. This worked! It seems wrong though. Is this really OK to do?

To be more clear, my work-around looks something like this:

<InfiniteLoader rowCount={loadedItems + 1} ...>
  ...
  <List rowCount={loadedItems} .../>
  ...
</Infiniteloader>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
gausiecommented, Aug 1, 2018

If anyone uses redux-saga or some other more complicated redux side-effects management, I had great success using https://github.com/erikras/redux-promise-listener to turn my dispatched actions into a Promise that InfiniteScroller can use.

1reaction
nickretallackcommented, Mar 16, 2018

Oh. There’s a comment about this in the code already. I guess I have to return a promise from loadMoreRows to make this work correctly? I guess that makes sense, and that’s how it’s explained in the documentation now that I take a closer look at it.

However, my app wasn’t written with promises. It uses Redux. My loadMoreRows function is a dispatched Thunk. Data comes back in through props. Is there a way to make this feature work without promises?

Read more comments on GitHub >

github_iconTop Results From Across the Web

InfiniteLoader and react-redux - Stack Overflow
as I understood from source code of react-virtualised, it is not required to return Promise from loadMoreRows function. although, if you don't, ...
Read more >
Using React-Virtualized InfiniteLoader, Autosizer, and Table ...
You'll need to return a promise that resolves once data is loaded from the external resource. For our use case, this function is...
Read more >
react-virtualized infinite loader simple example - CodeSandbox
React from "react"; · { InfiniteLoader, List } from "react-virtualized"; · needs to be imported once · LOADING = 1; · LOADED =...
Read more >
Understanding JavaScript Promises - DigitalOcean
You do not need to use promises for an asynchronous call. Prior to promises, we used callbacks. Callbacks are a function you call...
Read more >
React virtualized infinite scrolling table, how to | - abidibo.net
loadMoreRows : is a function that receives the startIndex and stopIndex and should return a Promise that should be resolved once the new...
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