Updating Arrays in State – React
6
Public whispers
6
Contributors
2026-07-24 09:44:56
First whispered
Public whispers on this page
Text Highlight2026-07-24 16:08:56
Original Highlight Excerpt
"Unfortunately, slice and splice are named similarly but are very different"
Whisper Note
Every single time I mix those up, it's a bug hunt.
Text Highlight2026-07-24 13:05:56
Original Highlight Excerpt
"every time you want to update an array, you’ll want to pass a new array to your state setting function."
Whisper Note
But what if the array is huge? Copying feels wasteful sometimes.
Text Highlight2026-07-24 12:56:56
Original Highlight Excerpt
"every time you want to update an array, you’ll want to pass a new array to your state setting function."
Whisper Note
So basically never mutate, just copy and replace. Got it.
Text Highlight2026-07-24 10:02:56
Original Highlight Excerpt
"Arrays are mutable in JavaScript, but you should treat them as immutable when you store them in state."
Whisper Note
I mean, it's just a guideline, but React's whole re-render thing kind of forces you to do it.
Text Highlight2026-07-24 09:53:56
Original Highlight Excerpt
"Arrays are mutable in JavaScript, but you should treat them as immutable when you store them in state."
Whisper Note
So true, I kept mutating state directly and my components wouldn't re-render. Learned that the hard way.
Text Highlight2026-07-24 09:44:56
Original Highlight Excerpt
"Arrays are mutable in JavaScript, but you should treat them as immutable when you store them in state."
Whisper Note
Yeah but copying arrays every time feels so wasteful, especially with big lists.
Share this page's whispers
Short link
https://domwhisper.com/s/780ad74e1370Embed snippet
<iframe src="https://domwhisper.com/embed/780ad74e1370" 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