loading is false | fetchMore
See original GitHub issueApollo’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:
- Created 6 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@seeden what about if you add
notifyOnNetworkStatusChange: true
to your options?thanks @cesarsolorzano it is working fine with notifyOnNetworkStatusChange.