Frameworks like React require that when you change the contents of an array or object you change it's reference. Or push another way that you don't change arrays but instead create new arrays with updated values (i.e. immutability).
There are older array methods that are incompatible with immutability because they alter the array in place and don't cghange the array reference. These are destructive methods.
Shown below are replacements for the array destructive methods (e.g. push
, pop
, splice
, sort
, etc.) that will create new array references with the updated data.
Solutions are provided using the spread operator and also the newer "change array by copy" methods (toSpliced
, toSorted
, toReversed
and with
).