Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useQuery: onCompleted called on every update #3353

Open
levrik opened this issue Aug 12, 2019 · 4 comments

Comments

@levrik
Copy link

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link

commented Aug 14, 2019

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

This comment has been minimized.

Copy link

commented Aug 16, 2019

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

@hwillson hwillson self-assigned this Aug 19, 2019

@rmalca

This comment has been minimized.

Copy link

commented Aug 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.