TypeError: Cannot assign to read only property
See original GitHub issueI’m keep getting this error
const { data, client } = useQuery(GET_GROUPS);
const onSkillSelect = id => {
setSkill({ variables: { id, skills: props.skills } });
};
const toggleSwitch = () => {
data.dataGroups[props.id].isSkillsDisabled = false;
client.writeData({ data: data });
}
when i’m trying to mutate something from the cache.
Uncaught TypeError: Cannot assign to read only property 'isSkillsDisabled' of object '#<Object>
I’m using 3.0 beta client react
import { gql, useMutation, useQuery } from '@apollo/client';
any idea how to override the cache?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cannot assign to read only property of Object in JavaScript
The error "Cannot assign to read only property of object" occurs when we try to change a property of an object that has...
Read more >Uncaught TypeError: Cannot assign to read only property
When you use Object.defineProperties , by default writable is set to false , so _year and edition are actually read only properties.
Read more >TypeError: "x" is read-only - JavaScript - MDN Web Docs
The JavaScript strict mode-only exception "is read-only" occurs when a global variable or object property that was assigned to is a read-only property....
Read more >[Cannot assign to read only property '<field_name>' of object ...
This type of error(Cannot assign to read-only property) generally occurs on update of public property @api decorator variable value.
Read more >Cannot assign to read only property 'X' of object ... - Reddit
This is most likely the issue, wired properties are immutable I believe. Best way to handle this is by using the spread operator...
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
this should work:
The Apollo Client 2.6 blog post explains the benefits of immutability, and why it’s becoming mandatory in Apollo Client 3.0: https://blog.apollographql.com/whats-new-in-apollo-client-2-6-b3acf28ecad1
If your first instinct in response to an error like this is to “override” the library that’s giving you the error, you’re starting off on the wrong foot. Please try to understand what’s going on first, or at least realize that the errors may be for your own good, before you jump to conclusions about possible workarounds. This issue tracker is for tracking bugs and features in the Apollo Client library, not a help desk for quick solutions to common problems that could be solved by reading the documentation on your own time.