Answer the question
In order to leave comments, you need to log in
Is it possible to use slice in React?
Please answer the question)
Is it correct to use slice to change the state in react? I read on some resources that this mutates the state, but in theory it returns a new array without changing the original
one. Please tell me the correct answer)
Answer the question
In order to leave comments, you need to log in
You can use it, but do not forget that slice, that spread operator they make a copy of only a flat object (array).
const arr = [0, 1, [2,3]]
const newArr = arr. slice(0)
newArr[2][0] = 'new data'
console.log(arr[2][0]) // new data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question