ApolloClient 3: Cannot update a component from inside the function body of a different component.
See original GitHub issuerelated 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"
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Fix "Cannot update component from inside function body of ...
The login screen calls setUser from the UserContext object on a successful login. This has been working fine but today I updated to...
Read more >warning: cannot update a component - You.com | The Search ...
To fix cannot update a component while rendering a different component warning with React, we should call functions from props inside the useEffect...
Read more >How I fixed 'Cannot update a component from inside the ...
In this short article I'll highlight why Cannot update a component from inside the function body of a different component warning happened ...
Read more >Queries - Apollo GraphQL Docs
As our query executes and the values of loading , error , and data change, the Dogs component can intelligently render different UI...
Read more >How to fix the "cannot update a component while rendering a ...
← flaviocopes.com. How to fix the "cannot update a component while rendering a different component" error in React. Published in 2020.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.