# Why does this reducer mutate earlier snapshots even though I spread the array?

**URL:** <https://forum.kirupa.com/t/why-does-this-reducer-mutate-earlier-snapshots-even-though-i-spread-the-array/679904>\
**Category:** web dev\
**Created:** [April 3, 2026, 3:00am UTC](https://forum.kirupa.com/t/why-does-this-reducer-mutate-earlier-snapshots-even-though-i-spread-the-array/679904 "2026-04-03T03:00:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [April 3, 2026, 3:00am UTC](https://forum.kirupa.com/t/why-does-this-reducer-mutate-earlier-snapshots-even-though-i-spread-the-array/679904/1 "2026-04-03T03:00:11Z")

</div>

I’m keeping a history of states for undo, but older snapshots change when I update a nested item. I thought spreading the array was enough. What’s the minimal fix here without pulling in Immer?

```js
const history = [[{ id: 1, done: false }]];

function nextState(prev) {
  const copy = [...prev];
  copy[0].done = true;
  return copy;
}

history.push(nextState(history[0]));
console.log(history[0][0].done, history[1][0].done);

```

Why do both values become `true`, and what’s the safest plain-JS pattern for nested updates in reducers?

Quelly

---

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [April 3, 2026, 3:14am UTC](https://forum.kirupa.com/t/why-does-this-reducer-mutate-earlier-snapshots-even-though-i-spread-the-array/679904/2 "2026-04-03T03:14:06Z")

</div>

`[...prev]` only clones the outer array, so `copy[0]` is still the same object as `prev[0]`.

Sora
