I tried to delete the item >>But when I click on the button and function does not work!!!!
Deleting in backend works but in frontend does not work!!
This is my function:
deleteblog = async id => {
// this.setState({ isLoading: true });
try {
const response = await fetch(
`http://localhost:8080/blog/delete/${id}`
);
const answer = await response.json();
if (answer.success) {
const blog = this.state.blog.filter(
contact => contact.id !== id
);
toast(`blog with id ${id} was successfully deleted!`);
this.setState({ blog });
} else {
console.log();
false });
}
} catch (err) {
console.log("error", err);
false });
}
};
This is the button:
<button type="button" onClick={this.deleteblog} class="btn btn-danger btn-rounded btn-sm my-0">delete</button>
This error that is showed in console log
GET http://localhost:8080/blog/delete/undefined 500 (Internal Server Error)
error SyntaxError: Unexpected token < in JSON at position 0
at BlogAdmin.deleteblog (Blogadmin.js:104)
And this >>> Blogadmin.js:104
====> const answer = await response.json();