Lets say i have an state and a variable bananas
state = {
bananas: []
}
And that there is some data in that array, so this means the array isn't empty.
I want to update only one element of the array. I have and index
variable with the index that I want to change.
My first try was this:
let newBananas = this.state.bananas
newBananas[index] = value
this.setState({bananas: newBananas })
but I don't think this is good.
I saw this question which helped me a little bit, but my case is different because I don't want to concat or add a new element to the array, I want to modify only one element at a given position.
What is the best way of doing this with good practices?