Updating Objects in State – React
5
公开标注数
5
参与人数
2026-07-16 09:18:06
首次 Whisper
本页的公开 Whisper
划选高亮2026-07-16 12:39:06
原文高亮摘录
“Mutation is only a problem when you change existing objects that are already in state”
Whisper 随想笔记
But what about mutable objects in a ref? Still risky, or is that fine too?
划选高亮2026-07-16 12:30:06
原文高亮摘录
“Mutation is only a problem when you change existing objects that are already in state”
Whisper 随想笔记
So true, I've debugged way too many issues caused by mutating state objects.
划选高亮2026-07-16 09:36:06
原文高亮摘录
“you should treat any JavaScript object that you put into state as read-only”
Whisper 随想笔记
Makes sense, but sometimes I just mutate and it works fine anyway.
划选高亮2026-07-16 09:27:06
原文高亮摘录
“you should treat any JavaScript object that you put into state as read-only”
Whisper 随想笔记
So does that mean I need to copy the whole object just to change one field?
划选高亮2026-07-16 09:18:06
原文高亮摘录
“you should treat any JavaScript object that you put into state as read-only”
Whisper 随想笔记
Honestly this is the rule I break the most, then regret it later.
分享本页 Whisper
短链接
https://domwhisper.com/s/6733305b7a37嵌入代码
<iframe src="https://domwhisper.com/embed/6733305b7a37" width="100%" height="480" style="border:0;border-radius:16px" loading="lazy"></iframe>