The array or object held by a useState state is changed in place, so no render follows

tx0/ts:state-mutated-in-placerecommendedwarningreliability/logicdepth fastbug

What it finds

items.push(item); setItems(items);: React compares the new state with the old one by identity. Changing the array or object of a state in place leaves it the same object, so React skips the render or shows stale values, and the old state that effects, memoized values and earlier renders still hold changes under them. A new array or object, as setItems([...items, item]), is a new state.

Reported are calls of push, pop, shift, unshift, splice, sort, reverse, fill and copyWithin on the value of a useState or useReducer pair whose setter the component uses, and assignments, ++, -- and delete on its members or elements, also further down as in form.address.city = city. The parameter of an updater function given to the setter, as in setItems(prev => { prev.push(item); return prev; }), is the state too. Only states known to hold plain data count: an array or object literal as the initial value, also returned by an initializer function, or an array, tuple, object literal, Array or Record type as the type argument. A state that holds an element, a class instance or another object with methods of its own is left alone.

From the rule's source, state_mutated_in_place.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:state-mutated-in-place" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:state-mutated-in-place] reason="..."

tx0 explain tx0/ts:state-mutated-in-place shows the same in the terminal. Found a false positive? Report it.