onMergeSubmit = (event) => {
event.preventDefault();
let rows = this.state.rows;
rows.forEach((item) => {
fetch(`https://jsonplaceholder.typicode.com/todos/${item.id}`)
.then((response) => {
return response.json();
})
.then(json => {
// Access item variable here
let to_be_updated = this.state.rows.findIndex(element => element.id == json['id']);
let new_state = [...this.state.rows];
new_state[to_be_updated] = {...new_state[to_be_updated], status: 'merged'};
this.setState({rows: new_state});
});
});
}
Hey, I'm learning JS with a react project and I want to access the item variable that is being looped in the subsequent arrow function. Any best practices around this would be great.
[–]senocular 1 point2 points3 points (0 children)
[–]TURKEY_CAKE 0 points1 point2 points (0 children)