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 (0)