Created
October 20, 2018 14:50
-
-
Save lomse/f87bac3bd4e5e509aa628a830f4c1d19 to your computer and use it in GitHub Desktop.
App.jsx updated to add new todos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import styled from 'styled-components' | |
import { generateId, addTodo } from '../lib/helper' | |
import TodoList from './TodoList' | |
import TodoForm from './TodoForm' | |
const Container = styled.div` | |
width: 250px; | |
margin: 10px auto; | |
font-family: Arial, Helvetica, sans-serif; | |
font-size: 13px; | |
` | |
class App extends Component { | |
constructor() { | |
super() | |
this.state = { | |
currentTodo: '', | |
todos: [] | |
} | |
this.handleSubmit = this.handleSubmit.bind(this) | |
this.handleOnchangeInput = this.handleOnchangeInput.bind(this) | |
} | |
handleSubmit = evt => { | |
evt.preventDefault() | |
const { currentTodo, todos } = this.state | |
const newTodo = { id: generateId(), name: currentTodo, isComplete: false } | |
const updatedTodos = addTodo(todos, newTodo) | |
this.setState({ todos: updatedTodos, currentTodo: '' }) | |
} | |
handleOnchangeInput = evt => { | |
this.setState({ currentTodo: evt.target.value }) | |
} | |
render() { | |
const { currentTodo, todos } = this.state | |
return ( | |
<Container> | |
<TodoForm | |
currentTodo={currentTodo} | |
handleSubmit={this.handleSubmit} | |
handleOnchangeInput={this.handleOnchangeInput} | |
/> | |
<TodoList todos={todos} /> | |
</Container> | |
) | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment