apollo-client: ApolloClient 3: Cannot update a component from inside the function body of a different component.
related to https://github.com/apollographql/react-apollo/issues/3863
Intended outcome:
useQuery
should not throw unintentional state changes warning.
Actual outcome:
Error thrown:
Warning: Cannot update a component from inside the function body of a different component.
How to reproduce the issue: probably the same as https://github.com/apollographql/react-apollo/issues/3863#issuecomment-608573622
Versions
"@apollo/client": "^3.0.0-beta.44"
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 16 (5 by maintainers)
@Banou26 i think yes
wrapping the apollo code inside a
useEffect
orsetTimeout
is not an efficient solutionI am getting this when using
reactiveVars
for pagination in a child component.I am on
@apollo/client@3.2.5
I have a
reactiveVar
:A
useQuery
call in my root / parent component:And in a child component when a button is pressed the reactive component is updated, which updates my query via a local client only field:
Then my data is updated via the other reactive var
This pattern for pagination (i.e. using reactive hooks + client schema fields) appears to cause this error to occur.
Thanks @dylanwulf , that is making the error go away, which is helpful because it looks like I have a different issue I need to track down that isn’t related, so now I can focus on that.
@coler-j I’ve just encountered the same issue, and fixed it by adding the reactive var mutation in an effect.
In your case, that would be: