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

Odd behavior with `loadMore`

Open tmpace opened this issue 7 years ago • 6 comments
trafficstars

First, here is the code I'm working with:

import React from 'react'
import InfiniteScroll from 'react-infinite-scroller'

const Step2Table = props => {
  const { urlLists } = props
  const hasMore = (urlLists.num_found === undefined) || (urlLists.num_found > urlLists.data.length)

  const items = urlLists.data.map((list, i) => {
    return (
      <tr key={i}>
        <td>{list.name}</td>
        <td>{list.date_created}</td>
      </tr>
    )
  })

  return (
    <div>
      <div role='tabpanel' className='tab-pane fade in active' id='cac-url-existing'>
        <div className='row'>
          <div className='col-lg-6'>
            <div className='form-group'>
              <label htmlFor='url-list-search' className='sr-only'>Search URL Lists</label>
              <input type='text' className='form-control' id='url-list-search' name='url-list-searc' placeholder='Search URL Lists' />
            </div>
          </div>
        </div>
      </div>

      <div className='row'>
        <div className='col-lg-12'>
          <div className='table-responsive'>
            <table className='table table-striped table-hover fixed-header' id='cac-url-existing-table'>
              <thead>
                <tr>
                  <th className='sortable' id='cac-url-list-name'>URL List Name</th>
                  <th className='sortable down' id='cac-url-list-date'>Create Date</th>
                </tr>
              </thead>
              <InfiniteScroll
                style={{ overflowY: 'auto', clear: 'both' }}
                element='tbody'
                loadMore={props.getUrlLists}
                hasMore={hasMore}
                loader={<tr key={0}><td >Loading...</td></tr>}
                useWindow={false}
              >
                { items }
              </InfiniteScroll>
            </table>
          </div>
        </div>
      </div>
    </div>
  )
}

export default Step2Table

Which results in loadMore being called once on initial load, the data loads, and the loading div stays on the page.

If I move the clear: 'both' to the loader component instead, it will load twice but then not load any longer, and the loading div still remains.

Not really sure what the deal is, but it's very confusing - hopefully I'm doing something simple incorrectly.

tmpace avatar Apr 25 '18 21:04 tmpace

Also, FWIW, I hasMore is true whenever the loading stops, I've checked this already.

tmpace avatar Apr 25 '18 22:04 tmpace

Another note, whenever I increase the threshold value, on initial page load, more calls to loadMore seem to happen. I'm guessing these calls are happening before the DOM has finished rendering, and then are prevented after for some reason.

tmpace avatar Apr 26 '18 00:04 tmpace

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

same issue here

currybob avatar Jan 23 '19 01:01 currybob

shouldn't the loadMore return a promise or something?

jimmywarting avatar Jan 30 '19 08:01 jimmywarting

@tmpace Have you found any solution for this issue? , I'm facing same!

vc-vishal avatar Nov 01 '21 05:11 vc-vishal