Skip to content

Commit a24f9ac

Browse files
committed
feat(ui): implement remove Todo functionality
1 parent ee2ef67 commit a24f9ac

File tree

1 file changed

+6
-1
lines changed
  • src/main/webapp/src/components

1 file changed

+6
-1
lines changed

src/main/webapp/src/components/todo.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import React, { useState, useEffect, useRef, useContext } from 'react';
22
import { TodosContext } from "../context/todos_context";
33

44
const Todo = function (props) {
5-
const { getTodo, updateTodo } = useContext(TodosContext);
5+
const { getTodo, updateTodo, deleteTodo } = useContext(TodosContext);
66
const [todo, setTodo] = useState(getTodo(props.id));
77

88
const toggleTodo = () => {
99
todo.completed = !todo.completed;
1010
updateTodo(todo);
1111
}
1212

13+
const removeTodo = () => {
14+
deleteTodo(props.id);
15+
}
16+
1317
return (
1418
<li>
1519
<div className="view">
@@ -21,6 +25,7 @@ const Todo = function (props) {
2125
<label>{todo.title}</label>
2226
<button
2327
className="destroy"
28+
onClick={removeTodo}
2429
></button>
2530
</div>
2631
<input

0 commit comments

Comments
 (0)