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.

loading is false | fetchMore

See original GitHub issue

Apollo’s “loading” is always false when I use fetchMore. I am using two “loading” states as you can see in the example. First one “loading” is from apollo and it is false when I try to use fetchMore. Second is “loadingMoreItems” and it is working fine because it is using state.

apollo-client@1.0.4 react-apollo@1.1.0

const GET_QUIZZES_QUERY = gql`
  query getQuizzes($cursor: String) {
    quizzes(cursor: $cursor) {
      id
      publishedAt 
      data
    }
  }
`;

@graphql(GET_QUIZZES_QUERY, {
  options: ({ location: { query } }) => ({
    variables: {
      cursor: null,
    },
  }),
  props: ({ data: { loading, quizzes, fetchMore }, ownProps: { location: { query } } }) => ({
    loading,
    quizzes,
    async loadMoreQuizzes() {
      return fetchMore({
        query: getQuizzes,
        variables: {
          cursor: quizzes && quizzes.length && quizzes[quizzes.length - 1].publishedAt,
        },
        updateQuery: (previousResult, { fetchMoreResult }) => {
          const previousQuizzes = previousResult.quizzes;
          const newQuizzes = fetchMoreResult.quizzes;

          return {
            quizzes: [...previousQuizzes, ...newQuizzes],
          };
        },
      });
    },
  }),
})
export default class Index extends Component {
  static propTypes = {
    loading: PropTypes.bool.isRequired,
    quizzes: PropTypes.array,
    loadMoreQuizzes: PropTypes.func.isRequired,
  };

  state = {};

  onLoadMore = async () => {
    const { loading } = this.props;
    if (loading) {
      return;
    }

    this.setState({
      loadingMoreItems: true,
    });

    await loadMoreQuizzes();

    this.setState({
      loadingMoreItems: false,
    });
  }

  render() {
    const { location: { query }, quizzes, loading } = this.props;
    const { redirectTo, loadingMoreItems } = this.state;
      return (
        <Redirect to={redirectTo} />
      );
    }

    console.log(loading, loadingMoreItems);

    const hasQuizzes = Boolean(quizzes && quizzes.length);

    return (
      <View className={style.root}>
 
        <Container>
          {hasQuizzes && (
            <Row>
              {quizzes.map(quiz => (
                <Column sm={3} key={quiz.id}>
                  <QuizThumb quiz={quiz} />
                </Column>
              ))}
            </Row>
          )}

          <Waypoint
            key={123}
            onEnter={this.onLoadMore}
          />

          {(loading || !!loadingMoreItems) && <Loading />}
        </Container>
      </View>
    );
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

68reactions
cesarsolorzanocommented, Apr 26, 2017

@seeden what about if you add notifyOnNetworkStatusChange: true to your options?

8reactions
seedencommented, Apr 27, 2017

thanks @cesarsolorzano it is working fine with notifyOnNetworkStatusChange.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fetchMore doesn't set loading to true (beta.52) #6354 - GitHub
When calling fetchMore , loading should be set to true. Actual outcome: It remains false and the data loads without this status ever...
Read more >
react apollo - Why would data.loading not become true during ...
console.log('render', User.length, loading, networkStatus). When I call data.fetchMore twice, I get: render 100 false 7 render 200 false 7 ...
Read more >
Core pagination API - Apollo GraphQL Docs
The fetchMore function. Pagination always involves sending followup queries to your GraphQL server to obtain additional pages of results. In Apollo Client, the ......
Read more >
Use fetchMore and merge field policies to dynamically load ...
For this, we'll start off by looking at the fetchMore utility, that is provided by the useQuery hook, to trigger loading of more...
Read more >
Infinite Scroll With Apollo Client 3 - Trevor Blades
A fetchMore query is not currently in progress · We know there are still additional pages of data to load · We haven't...
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