diff --git a/src/App.js b/src/App.js index 838aa71..005acd2 100644 --- a/src/App.js +++ b/src/App.js @@ -1,71 +1,58 @@ -import React, { Component } from 'react' +import React, { useState } from 'react' import uuidv4 from 'uuid/v4' import Todo from './Todo' -class App extends Component { - state = { - inputValue: '', - todos: {} - } +const App = () => { + const [inputValue, setInputValue] = useState('') + const [todos, setTodos] = useState({}) - addTodo = todo => { - this.setState({ - inputValue: '', - todos: { - ...this.state.todos, - [uuidv4()]: todo - } + const addTodo = todo => { + setInputValue('') + setTodos({ + ...todos, + [uuidv4()]: todo }) } - toggleTodo = id => { - this.setState({ - todos: { - ...this.state.todos, - [id]: { - ...this.state.todos[id], - checked: !this.state.todos[id].checked - } + const toggleTodo = id => { + setTodos({ + ...todos, + [id]: { + ...todos[id], + checked: !todos[id].checked } }) } - onKeyDownHandler = event => { + const onKeyDownHandler = event => { if (event.keyCode === 13) { - this.addTodo({ - value: this.state.inputValue, + addTodo({ + value: inputValue, checked: false }) } } - onChange = event => { - this.setState({ - inputValue: event.target.value - }) - } - - render() { - const { inputValue, todos } = this.state - return ( -
-

To Do

- - -
- ) - } + const onChange = event => setInputValue(event.target.value) + + return ( +
+

To Do

+ + +
+ ) } export default App diff --git a/src/Todo.js b/src/Todo.js index 8a7ae73..f964fa7 100644 --- a/src/Todo.js +++ b/src/Todo.js @@ -1,23 +1,17 @@ -import React, { Component } from 'react' +import React from 'react' import classNames from 'classnames' -class Todo extends Component { - onClick = () => this.props.toggleTodo(this.props.id) - render() { - const { id, todo } = this.props - return ( -
  • - - {todo.value} -
  • - ) - } -} +const Todo = ({ id, todo: { value, checked }, toggleTodo }) => ( +
  • toggleTodo(id)} + className={classNames('todo', { + 'opacity-25': checked + })} + > + + {value} +
  • +) export default Todo