React question detail
What are the preferred and non-preferred array operations for updating the state?
The below table represent preferred and non-preferred array operations for updating the component state.
| Action | Preferred | Non-preferred |
|---|---|---|
| Adding | concat, [...arr] | push, unshift |
| Removing | filter, slice | pop, shift, splice |
| Replacing | map | splice, arr[i] = someValue |
| sorting | copying to new array | reverse, sort |
If you use Immer library then you can able to use all array methods without any problem.