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

levrik opened this issue Aug 13, 2019 · 3 comments


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.

Pay attention to the peoples count.


@apollo/react-hooks 3.0.0


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


This comment has been minimized.

Copy link

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.


This comment has been minimized.

Copy link

commented Aug 18, 2019

I've updated the example to @lensbart advice, seems working better now. Wtyt?

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