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.

Add an extra option isLoading

See original GitHub issue

currently, we only have an option hasMore to indicate if we have more options or not. In the code, we have hasMore && to show or not the Loader(spinner).

The problem is: If I set hasMore to true, I get the Loader in the screen, but the component does hundreds of requests. If I set hasMore to false when I’m doing the request, I avoid the hundreds of requests, but I don’t get the Loader.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:9

github_iconTop GitHub Comments

14reactions
viniciusdacalcommented, Jun 30, 2017

@gautier-lefebvre Thanks for your advice. Indeed, that would work!

But I think, as we already have a loader in the component, let’s make it work properly.

5reactions
viniciusdacalcommented, Oct 12, 2017

I created a wrapper component that accepts the isLoading props. Then, instead of using react-infinite-scroller directly, I just use my wrapper:

import React, { Component } from 'react';
import InfiniteScroller from 'react-infinite-scroller';

const loader = (<UILoaderContainer />);

class InfiniteScroll extends Component {
  constructor(props) {
    super(props);
    this.handleInfiniteLoad = this.handleInfiniteLoad.bind(this);
  }

  handleInfiniteLoad() {
    const { isLoading, hasMore, children, loadMore } = this.props;

    if (!children || isLoading || !hasMore) {
      return;
    }

    loadMore();
  }

  render() {
    const { isLoading, hasMore, children } = this.props;
    return (
      <InfiniteScroller
        initialLoad={false}
        loader={null}
        className="infinite-scroll"
        hasMore={hasMore && !isLoading}
        loadMore={this.handleInfiniteLoad}
      >
        {children}
        {isLoading && loader}
      </InfiniteScroller>
    );
  }
}

export default InfiniteScroll;

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Select : How to display 'Loading...' while loading options
You can achieve this by creating a variable in your state that will hold the status of the loading. You then set this...
Read more >
Components - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
Add/Remove options from select box - ServiceNow Community
Solved: Hello! In a catalog item, i have 2 variables, VAR A and VAR B. Var A has 2 options - Option 1...
Read more >
Mutations | TanStack Query Docs
For this purpose, React Query exports a useMutation hook. Here's an example of a mutation that adds a new todo to the server:...
Read more >
Queries - Redux Toolkit
If the query callback needs additional data to generate the URL, it should be written to take a ... Example of all query...
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