I am working on a React frontend with a delete method which deletes an item in the database. Having a hard time with the following code.
deleteFromDB = idTodelete => {
let objIdToDelete = null;
this.state.data.forEach(dat => {
if (dat.id == idTodelete) {
objIdToDelete = dat._id;
}
});
This is the method called after entering the ID to be deleted and this modifies the state by deleting the item corresponding to the ID