Created
January 30, 2018 23:20
-
-
Save pinkmomo027/fd57c9722c2e2c2b9dc63d7a88c4170c 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
| const List = props => ( | |
| <ul> | |
| { | |
| props.items.map( (item, index) => <li key={index}>{item}</li> ) | |
| } | |
| </ul> | |
| ) | |
| class TodoList extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| items: [], | |
| term: '' | |
| } | |
| this.handleChange = this.handleChange.bind(this); | |
| } | |
| handleChange = (e) => { | |
| this.setState({ | |
| term: e.target.value | |
| }); | |
| } | |
| handleSubmit = (e) => { | |
| e.preventDefault(); | |
| this.setState({ | |
| term: '', | |
| items: [...this.state.items, this.state.term] | |
| }); | |
| } | |
| render() { | |
| const buttonStyle = { | |
| height: 19, | |
| marginLeft: 5, | |
| borderRadius: 10 | |
| } | |
| return ( | |
| <div> | |
| <h4>Todo List</h4> | |
| <form onSubmit={this.handleSubmit}> | |
| <input | |
| type='text' | |
| value={this.state.term} | |
| onChange={this.handleChange} | |
| placeholder="Enter Todo" /> | |
| <button type='submit' style={buttonStyle}>Add</button> | |
| </form> | |
| <List items={this.state.items} /> | |
| </div> | |
| ); | |
| } | |
| } | |
| ReactDOM.render(<TodoList />, document.querySelector('#root')); | |
| // HTML | |
| // <div id='root'></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment