Immutable updates

An immutable update means never modifying state in place, but producing a new value: copying an object with {...obj}, an array with map, filter or [...arr]. React compares references to decide whether to re-render, so a direct mutation is not detected.

Example

setTodos(todos.map(t => t.id === id ? { ...t, fait: true } : t));

Related concepts

The whole glossary