Setting an object value inside an atom returns "Cannot assign to read only property 'xxxxx' of object '#<Object>'"
See original GitHub issueI am trying to edit a key of ‘activeCourse’ inside an object of an atom value. However, whenever i do so it returns the error:
Cannot assign to read only property 'activeCourse' of object '#<Object>'
The atom is called ‘trainingAtom’ and default value is an array of objects:
[
{
_id: '5fc42caa244ccadea8e2f263',
activeCourse: 'r4r3545243j',
activeDetail: null,
},
{
_id: '5fc42caa244ceecadea8e2f263',
activeCourse: null,
activeDetail: null,
},
]
I am using the following function within my component:
const [test, setTest] = useRecoilState(trainingAtom);
useEffect(() => {
let _test = [...test];
const index = _test.findIndex((val) => val._id === id);
_test[index].activeCourse = 123456;
setTest(_test);
}, [id]);
This function works if I use normal React state - but anything inside Recoil throws the error.
Note, I have also tried to use the set
function inside a selector but it gives the same error.
What am I doing wrong?
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Cannot assign to read only property 'url' of object '#<Object>'
Show activity on this post. I tried changing a key's value inside my object, but it seems like I have been mutating the...
Read more >“TypeError: Cannot assign to read only property of object ' ...
ERROR TypeError : Cannot assign to read only property 'value' of object '[object Object]' ... 'Switch' is not exported from 'react-router-dom'. ch warning....
Read more >Webpack: Cannot assign to read only property 'exports'
Hi, I need to use an external library crypto when running my k6 tests. I'm using the example here: https://github.com/k6io/k6-es6 However on ...
Read more >Configuration - IGSS
Reference to the Application object. CurrentAreaName As String (Read Only). Return the name of the current area as selected in supervise. When running...
Read more >Troubleshooting Compiler Errors - NetFort
An attempt was made to assign a value to a read-only system variable. ... Review the object class, and correct it to match...
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
have you tried using updater instead of value? like this:
@drarmstr I trying to use updater as @cbuv suggests, but in my case, I have list of big deep nested objects. For example if I need just to change
status
inlots[].clients[].bid.status
, I have to write like below to defrost whole [lot] object and avoid errorShould I use dangerouslyAllowMutability or it is possible in any other more simple way?