I am trying to change a value of an array that is in an another array using React.
Here is my array:
routes = [
{
id: 1,
points: [{id, address, status}, {id, address, status},]
},
{
id: 2,
points: [{id, address, status}, {id, address, status},]
},
]
And how I have set it up. When user clicks on "Accept" then the status of that specific point should change.
{routes.map((route, i) => (
<div>...</div>
{route.points.map((point, i) => (
<Button onClick={() => this.onAcceptClicked(route.points)>Accept</Button>
))}
))}
Here I am trying to change the value but I am missing something or doing everything completely wrong. Status of that specific point should be set to 2.
onAcceptClicked = (points) => {
const myNewArray = Object.assign([...points], {
[index]: {
...deliveryPoints[index],
status: 2
}
});
//this.setState({ points: myNewArray }); ... not sure how to do this part
}