Immutability and Why React Cares
Understand why React state updates require new objects/arrays rather than in-place mutation, and how this connects to change detection.
React determines whether a component needs to re-render by comparing the previous and next state (and props) values, and for objects and arrays it does this comparison by reference (Object.is / ===), not by deeply inspecting every field. If you mutate an object in place and pass the same reference back to a setter, React sees the identical reference and may conclude nothing changed, skipping the re-render even though the data 'looks' different.
It's like handing someone a photocopy of a document with your edits already applied (a new reference) versus scribbling directly on their original copy and handing the exact same physical page back — from the receptionist's (React's) point of view checking 'is this the same page I already filed?', the scribbled-on original still looks like the same page.