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: useEffect doesn't run on cache update #3357

Open
levrik opened this issue Aug 13, 2019 · 3 comments

Comments

@levrik
Copy link

commented Aug 13, 2019

Intended outcome: After updating the cache via cache.writeQuery inside update of an mutation, I expect the updated query results to cause useEffect to run again if data is passed as dependency.

Actual outcome: A re-render was triggered but useEffect which have data passed as dependency doesn't run again. It seems like the reference to data stays the same.

How to reproduce the issue:

I used useMemo in this example but the result is the same with useEffect, useCallback and similar.

https://codesandbox.io/s/apollo-client-error-template-dj88f

Pay attention to the peoples count.

Version

@apollo/react-hooks 3.0.0

@lensbart

This comment has been minimized.

Copy link

commented Aug 13, 2019

Have you tried avoiding to mutate the local store data? I had a somewhat similar issue (component not rerendering although the store had been updated), and this turned out to solve my problem. You can configure your Apollo Client instance to enforce immutability, which might come with a performance benefit as well: see apollographql/apollo-client#4543

@levrik

This comment has been minimized.

Copy link
Author

commented Aug 14, 2019

@lensbart Actually I'm mutating the array but then creating a new array out of it when passing it to the writeQuery method.
Thanks for the pointer. I'll try this option.

@pawelkleczek10c

This comment has been minimized.

Copy link

commented Aug 18, 2019

I've updated the example to @lensbart advice, seems working better now. Wtyt?
https://codesandbox.io/s/apollo-client-error-template-lcber

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