50
rated 0 times
[
54]
[
4]
/ answers: 1 / hits: 40799
/ 7 Years ago, mon, august 14, 2017, 12:00:00
I'm replacing an item in a react state array by using the ... spread syntax. This works:
let newImages = [...this.state.images]
newImages[4] = updatedImage
this.setState({images:newImages})
Would it be possible to do this in one line of code? Something like this? (this doesn't work obviously...)
this.setState({images: [...this.state.images, [4]:updatedImage})
More From » reactjs