, @mayank-shukla ( 2: ), Array.splice:
const replacement = 'B';
let copy = [...this.state.ids]
copy.splice(index, 1, replacement)
this.setState({
ids: copy,
})
REPL
:
Array.splice ; , , - . .- ,
Array.splice (). AKA: , setState, .
To continue exploring the shallow and deep copies from point 1, note that if you replace object references (instead of string literals in the question), you need to use something like lodash cloneDeep .
Although there are several other ways around this .
You can also read more about shallow and deep on SO itself .
source
share