Created
June 20, 2018 19:54
-
-
Save basekays/012b1c3ccf6dd2574816de8a73dd42d6 to your computer and use it in GitHub Desktop.
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
| class TodoList extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| todoItems: [ | |
| 'workout', | |
| ], | |
| } | |
| this.handleSubmit= this.handleSubmit.bind(this); | |
| } | |
| handleSubmit(event) { | |
| event.preventDefault(); | |
| const newItem = event.target.newItem.value; | |
| this.setState({ | |
| todoItems: [...this.state.todoItems, newItem] | |
| }) | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <h4>Todo List</h4> | |
| <div> | |
| <form onSubmit={this.handleSubmit}> | |
| <input | |
| name="newItem" | |
| type="text" | |
| placeholder="enter new item" | |
| /> | |
| <button | |
| type="submit" | |
| > | |
| Add | |
| </button> | |
| </form> | |
| </div> | |
| <div> | |
| {this.state.todoItems.map((item) => ( | |
| <div> | |
| {item} | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| } | |
| } | |
| ReactDOM.render( <TodoList />, document.getElementById('root')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment