Why is useState not triggering re-render?

You’re calling setNumbers and passing it the array it already has. You’ve changed one of its values but it’s still the same array, and I suspect React doesn’t see any reason to re-render because state hasn’t changed; the new array is the old array.

One easy way to avoid this is by spreading the array into a new array:

setNumbers([...old])

Leave a Comment