Created
June 7, 2017 01:31
-
-
Save goofmint/ff855e59e708d7d2bf602ca8636988ea to your computer and use it in GitHub Desktop.
This file contains 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
export default class TodoList extends Component { | |
state = { todos: [], text: '' }; | |
setText = e => { | |
this.setState({ text: e.target.value }); | |
}; | |
addTodo = () => { | |
let { todos, text } = this.state; | |
todos = todos.concat({ text }); | |
this.setState({ todos, text: '' }); | |
}; | |
render({ }, { todos, text }) { | |
return ( | |
<form onSubmit={this.addTodo} action="javascript:"> | |
<input value={text} onInput={this.setText} /> | |
<button type="submit">Add</button> | |
<ul> | |
{ todos.map( todo => ( | |
<li>{todo.text}</li> | |
)) } | |
</ul> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment