DEV Community

Discussion on: Cheat Sheet for Updating Objects and Arrays in React State

Collapse
 
ace540i profile image
Michael Darretta

isn't this mutation?

const newTodos = [...todos];
newTodos[index] = todo;

Collapse
 
brianl09 profile image
brianL09

The spread operator [...] creates a shallow copy and thus doesn't mutate the original state directly.