update array of objects with use state
const toggleDone = (id) => { console.log(id); // loop over the todos list and find the provided id. let updatedList = state.todos.map(item => { if (item.id == id){ return {...item, done: !item.done}; //gets everything that was already in item, and updates "done" } return item; // else return unmodified item }); setState({todos: updatedList}); // set state to new object with updated list }
Source: stackoverflow.com