Updating Objects in State – React
5
Public whispers
5
Contributors
2026-07-16 09:18:06
First whispered
Public whispers on this page
Text Highlight2026-07-16 12:39:06
Original Highlight Excerpt
"Mutation is only a problem when you change existing objects that are already in state"
Whisper Note
But what about mutable objects in a ref? Still risky, or is that fine too?
Text Highlight2026-07-16 12:30:06
Original Highlight Excerpt
"Mutation is only a problem when you change existing objects that are already in state"
Whisper Note
So true, I've debugged way too many issues caused by mutating state objects.
Text Highlight2026-07-16 09:36:06
Original Highlight Excerpt
"you should treat any JavaScript object that you put into state as read-only"
Whisper Note
Makes sense, but sometimes I just mutate and it works fine anyway.
Text Highlight2026-07-16 09:27:06
Original Highlight Excerpt
"you should treat any JavaScript object that you put into state as read-only"
Whisper Note
So does that mean I need to copy the whole object just to change one field?
Text Highlight2026-07-16 09:18:06
Original Highlight Excerpt
"you should treat any JavaScript object that you put into state as read-only"
Whisper Note
Honestly this is the rule I break the most, then regret it later.
Share this page's whispers
Short link
https://domwhisper.com/s/6733305b7a37Embed snippet
<iframe src="https://domwhisper.com/embed/6733305b7a37" width="100%" height="480" style="border:0;border-radius:16px" loading="lazy"></iframe>See what people are discussing on react.dev
Install DomWhisper to view live whispers as you browse, and join the discussion.
Get the extension