Skip to content

Commit

Permalink
feat(ui): implement remove Todo functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bsbodden committed Feb 20, 2021
1 parent ee2ef67 commit a24f9ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/webapp/src/components/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import React, { useState, useEffect, useRef, useContext } from 'react';
import { TodosContext } from "../context/todos_context";

const Todo = function (props) {
const { getTodo, updateTodo } = useContext(TodosContext);
const { getTodo, updateTodo, deleteTodo } = useContext(TodosContext);
const [todo, setTodo] = useState(getTodo(props.id));

const toggleTodo = () => {
todo.completed = !todo.completed;
updateTodo(todo);
}

const removeTodo = () => {
deleteTodo(props.id);
}

return (
<li>
<div className="view">
Expand All @@ -21,6 +25,7 @@ const Todo = function (props) {
<label>{todo.title}</label>
<button
className="destroy"
onClick={removeTodo}
></button>
</div>
<input
Expand Down

0 comments on commit a24f9ac

Please sign in to comment.