I am making cookbook app in React. The recipes are fetched via API. I would like to know how to update state of data after deleting some recipe with DELETE request. Right now, I need to refresh the app to receive updated data. Can you explain to me how to update the state after DELETE request?
the delete function look like this:
function handleDelete() {
fetch(url_recipes + id,
{method: 'DELETE'})
.then(response => response.text())
.then(json => console.log("Deleted!", json))
.catch(error => console.log('Error message: ', error));
navigate("/")
}
in the Recipe List I am using useFetch to retrieve the data:
const { data: recipes, error, isPending } = useFetch(url_recipes);