FrontendDeveloper.in

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.

ActionPreferredNon-preferred
Addingconcat, [...arr]push, unshift
Removingfilter, slicepop, shift, splice
Replacingmapsplice, arr[i] = someValue
sortingcopying to new arrayreverse, sort

If you use Immer library then you can able to use all array methods without any problem.

Back to all React questions
Get LinkedIn Premium at Rs 399