diff --git a/client/src/App.js b/client/src/App.js index 48d41f7..12576e9 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -17,18 +17,20 @@ function App() { .catch((err) => console.error("Error: ", err)); } - const completeTodo = async id => { - const data = await fetch(api_base + '/todo/complete/' + id).then(res => res.json()); + const completeTodo = async (id) => { + const response = await fetch(api + "/todo/complete/" + id); + const data = await response.json(); + + setTodos((todos) => + todos.map((todo) => { + if (todo._id === data._id) { + todo.complete = data.complete; + } + return todo; + }) + ); + }; - setTodos(todos => todos.map(todo => { - if (todo._id === data._id) { - todo.complete = data.complete; - } - - return todo; - })); - - } const addTodo = async () => { const data = await fetch(api_base + "/todo/new", {