Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/TodoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export default function TodoItem({ todo }: TodoItemProps) {
dispatch({ type: 'TOGGLE_COMPLETED', id });
};

const handleDelete = () => {
dispatch({ type: 'DELETE_TODO', id });
};

return (
<Container>
<CheckBox checked={completed} onClick={handleClick} />
<Content checked={completed}>{content}</Content>
<Delete />
<Delete onClick={handleDelete} />
</Container>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/todoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드에서 보다싶이 api.deleteTodo 함수는 삭제된 결과의 배열을 return 값으로 반환하고 있기 때문에,
굳이 api.getTodos() 호출할 필요 없이 아래처럼 바꾸면 됩니다!

Suggested change
todos: api.getTodos(),
case 'DELETE_TODO':
return {
...state,
todos: api.deleteTodo(action.id),
};

};
case 'TOGGLE_COMPLETED':
return {
Expand Down