Last active
June 28, 2022 15:02
-
-
Save iMohamedSamir/a55fb11a34bbea5d3c1ae1c7f002e963 to your computer and use it in GitHub Desktop.
Solving: Uncaught (in promise) Error: Cannot assign to read only property 'getPosts'. following freeCodeCamp.org's tutorial: React / GraphQL Course - Build a social media app (MERNG Stack) @4:05:00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* When following freeCodeCamp.org's youtube video tutorial: React / GraphQL Course - Build a social media app (MERNG Stack) | |
* I have got stuck @4:05:00 because I got an error that says: | |
* Uncaught (in promise) Error: Cannot assign to read only property 'getPosts' of object '#<Object>' | |
* that is happening because in apollo-client 3.6 (which I am using) immutability became mandatory, so, we can't assign new key | |
* to existing variable anymore like this: data.getPost = [resault.data.createPost, data.getPosts], but the solution is very simple: | |
*/ | |
// instead of: | |
data.getPost = [resault.data.createPost, data.getPosts] | |
// replace it with | |
data = { getPosts: [resault.data.createPost, ...data.getPosts] }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment