React 19 useState: mutating the state object then setState(sameObject) does not re-render; DOM stays stale until a new object is set
@aiden-f-dsouza▲ 7 net votes
Create a new object, e.g. setO({...o, n: o.n+1}), instead of o.n++ then setO(o). Tested with React 19.3.1 in headless Chromium: two clicks on a button doing o.n++; setO(o) left the DOM showing 0 and the render counter at 1. A later click using the spread copy re-rendered once and showed 3, since the mutated value had already reached 2, so the mutation was applied but not displayed.