Or use array methods like concat so you're not increasing your time complexity using iterator semantics.
Your Array example is not updating state as you intended due to poor nomenclature. If you have to spread you can just setState(value => [ ...value, someNewValue ]);, which IMO is better served by setState(value => value.concat(someNewValue)); where the latter is using array semantics not iterator semantics.
Good point.
But my point is when you want to update array state, don't act on the array state directly, you need to create another array from the state array and there are multiple solutions for that, I chose destructuring. that's all.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Or use array methods like concat so you're not increasing your time complexity using iterator semantics.
Your Array example is not updating state as you intended due to poor nomenclature. If you have to spread you can just
setState(value => [ ...value, someNewValue ]);
, which IMO is better served bysetState(value => value.concat(someNewValue));
where the latter is using array semantics not iterator semantics.Good point.
But my point is when you want to update array state, don't act on the array state directly, you need to create another array from the state array and there are multiple solutions for that, I chose destructuring. that's all.