Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

useQuery: onCompleted called on every update #3353

Closed
levrik opened this issue Aug 12, 2019 · 5 comments
Closed

useQuery: onCompleted called on every update #3353

levrik opened this issue Aug 12, 2019 · 5 comments
Assignees

Comments

@levrik
Copy link

levrik commented Aug 12, 2019

Intended outcome:

Updating some state in onCompleted based on the result from a query.

Actual outcome:

Ending up in an endless loop, since every update to the component which calls the query, results in onCompleted getting called again.

How to reproduce the issue:

https://codesandbox.io/embed/apollo-client-error-template-78jbq
Pay attention to the console.

Version

@apollo/react-hooks 3.0.0

@levrik
Copy link
Author

levrik commented Aug 12, 2019

Ah. I see where the issue lies.
The passed onCompleted callback is different on every render so it re-triggers.
Actually no re-fetch is triggered. Is this behavior expected?

@PovilasSlekys
Copy link

I noticed the same issue. This seems to be solved by passing variables: {} to the query options in the case where the query has no variables as in the example.

@oceandrama
Copy link

@PovilasSlekys Thanks, you saved a few hours of my life!

@hwillson hwillson self-assigned this Aug 19, 2019
@rmalca
Copy link

rmalca commented Aug 20, 2019

@PovilasSlekys I don't know why but it's works!

@hwillson
Copy link
Member

This has been fixed by #3419, and will be released shortly. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants