Skip to content
Permalink
Browse files

toggle todo

  • Loading branch information...
rwieruch committed Apr 6, 2019
1 parent 37144e9 commit 8f727cebe7079a0f72d6104e63712e1026ed1806
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/App.js
@@ -23,6 +23,18 @@ const App = () => {
const [todos, setTodos] = useState(initalTodos);
const [task, setTask] = useState('');

const handleChangeCheckbox = id => {
setTodos(
todos.map(todo => {
if (todo.id === id) {
return { ...todo, complete: !todo.complete };
} else {
return todo;
}
})
);
};

const handleChangeInput = event => {
setTask(event.target.value);
};
@@ -42,7 +54,14 @@ const App = () => {
<ul>
{todos.map(todo => (
<li key={todo.id}>
<label>{todo.task}</label>
<label>
<input
type="checkbox"
checked={todo.complete}
onChange={() => handleChangeCheckbox(todo.id)}
/>
{todo.task}
</label>
</li>
))}
</ul>

0 comments on commit 8f727ce

Please sign in to comment.
You can’t perform that action at this time.