From d7c6012267ea670308ca0392d192a5fcd55db396 Mon Sep 17 00:00:00 2001 From: MiryangJung Date: Sun, 3 Oct 2021 17:26:08 +0900 Subject: [PATCH] featt Delete --- src/components/TodoItem.tsx | 6 +++++- src/contexts/todoContext.tsx | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/TodoItem.tsx b/src/components/TodoItem.tsx index 4f10957..8bda0f8 100644 --- a/src/components/TodoItem.tsx +++ b/src/components/TodoItem.tsx @@ -19,11 +19,15 @@ export default function TodoItem({ todo }: TodoItemProps) { dispatch({ type: 'TOGGLE_COMPLETED', id }); }; + const handleDelete = () => { + dispatch({ type: 'DELETE_TODO', id }); + }; + return ( {content} - + ); } diff --git a/src/contexts/todoContext.tsx b/src/contexts/todoContext.tsx index bf0c394..4702c9e 100644 --- a/src/contexts/todoContext.tsx +++ b/src/contexts/todoContext.tsx @@ -44,10 +44,10 @@ const reducer = (state: TodoState, action: Action): TodoState => { // todos: }; case 'DELETE_TODO': + api.deleteTodo(action.id); return { ...state, - // TODO: todo가 삭제 되었을 때 action.id 값을 이용하여 todos 가 삭제 되도록 수정하기 - // todos: + todos: api.getTodos(), }; case 'TOGGLE_COMPLETED': return {