Skip to content

Commit 2ea221b

Browse files
authored
Merge pull request #5 from cnbrkkaya/DeleteFix
Control delete request response before updating component state
2 parents ea88985 + 0dfba11 commit 2ea221b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/App.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ const App = () => {
5656

5757
// Delete Task
5858
const deleteTask = async (id) => {
59-
await fetch(`http://localhost:5000/tasks/${id}`, {
59+
const res = await fetch(`http://localhost:5000/tasks/${id}`, {
6060
method: 'DELETE',
6161
})
62-
63-
setTasks(tasks.filter((task) => task.id !== id))
62+
//We should control the response status to decide if we will change the state or not.
63+
res.status === 200
64+
? setTasks(tasks.filter((task) => task.id !== id))
65+
: alert('Error Deleting This Task')
6466
}
6567

6668
// Toggle Reminder

0 commit comments

Comments
 (0)