I am trying to flip the state from false to true when the checkbox is toggled but an not sure how to do it.
class App extends Component {
state = {
todos: [],
currentTodo: {
note: '',
id: ''
}
};
handleInput = (evt) => {
this.setState({
currentTodo: {
id: Date.now(),
note: evt.target.value,
isCompleted: false
}
});
};
handleSubmit = (evt) => {
evt.preventDefault();
const newTodo = this.state.currentTodo;
if (newTodo.note !== '') {
const todos = [ ...this.state.todos, newTodo ];
this.setState({
todos: todos,
currentTodo: {
note: '',
id: '',
isCompleted: false
}
});
}
};
completedItem = (todosCompleted) => {
console.log({ todosCompleted });
this.setState({
todos: !this.state.isCompleted
});
};
render() {
return (
<section className="todoapp">
<header className="header">
<h1>todos</h1>
<form onSubmit={this.handleSubmit}>
<input
onChange={this.handleInput}
value={this.state.currentTodo.note}
id="todo"
className="new-todo"
placeholder="What needs to be done?"
autoFocus
/>
</form>
</header>
<TodoList
completedItem={this.completedItem} deleteItem=
{this.deleteItem}
/>
<footer className="footer">
<span className="todo-count">
<strong>{this.state.todos.length}</strong>
{this.state.todos.length <= 1 ? 'item' : 'items'}{' '}
left
</span>
</footer>
</section>
);
}
}
class TodoList extends Component {
render() {
return (
<section className="main">
<ul className="todo-list">
{this.props.todos.map((todo) => (
<TodoItem
key={todo.id}
title={todo.note}
deleteItem={(evt) => this.props.deleteItem(todo.id)}
completedItem={(evt) => this.props.deleteItem(todo.isCompleted)}
/>
))}
</ul>
</section>
);
}
}