Incoming arg to updater cannot be modified
See original GitHub issueWhen using the update function from ShiftDB, the prevState argument appears to be ‘read-only’. I’m unaware of any spec which defines such functionality, so as of now I assume this is unintended.
update((someData = { key: [] }) => {
someData.key.push('item');
return someData;
});
The above code results in the following error
TypeError: Cannot assign to read only property 'key' of #<Object>
I suggest initially and immediately reverting this to the specced behavior, and then we can open a discussion regarding future design.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Is modifying an incoming parameter an antipattern? [closed]
It is an error to modify an in parameter or read an out parameter, but any changes to an in out parameter are...
Read more >Java: Modifying parameter passed as a Reference
I have to update the value of result parameter before method returns. For example if the value of result was ABC when the...
Read more >Remedy AR System Server- Email - Approval e-mail is getting ...
Remedy AR System Server- Email - Approval e-mail is getting rejected showing "The modify key in the incoming modify action email message is...
Read more >Update your stack set - AWS CloudFormation
In this walkthrough, we are using the current template. Choose Use current template, and then choose Next. On the Specify StackSet details page,...
Read more >Windows Update error codes by component - Microsoft Learn
Learn about reference information for Windows Update error codes, including automatic update errors, UI errors, and reporter errors.
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 Free
Top 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

I don’t mind removing the actual freezing, (also, I think it’s a must in production) For all other means, this should be considered immutable to allow us to handle the data changes for the user more efficiently. I would also like to stay consistent with
React.setStateReact Documentation
from: https://reactjs.org/docs/state-and-lifecycle.html#using-state-correctly
So in react it’s not allowed and frowned upon mutating the state. The whole react mechanism works on the assumption that everything is immutable.
React with TypeScript
I wrote this code:
So leaving this object read only is perfectly consistent with
ReactLGTM, pending our launch and user feedback.