In React, a component re-renders only when the state reference changes.
Some array methods DO NOT create a new reference, so React wonβt re-render π«
β Methods that DO NOT change reference (Mutating methods)
These modify the same array/object in memory:
push
pop
shift
unshift
sort
reverse
splice
fill
copyWithin
β οΈ Using these directly on React state may NOT trigger a re-render
// β Wrong
state.items.push(1);
setItems(state.items); // same reference
β Methods that CREATE a new reference (Safe for React)
These return a new array, so React detects the change:
map
filter
concat
slice
flat
flatMap
toSorted
toReversed
toSpliced
// β
Correct
setItems(prev => [...prev, 1]);
π§ Key Rule to Remember
React compares references, not values.
Same reference = β no render
New reference = β
re-render
π₯ One-line takeaway
βMutating methods keep the same reference, so React wonβt re-render. Always return a new reference when updating state.β

Top comments (1)
Hey, you forgot about when the weather changes πππ and just everything re-renders