Created
January 17, 2018 17:00
-
-
Save xavierartot/7b3ed01b075cb1c9953b56708a62a4b8 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
//Improvment from this tutorial: https://medium.com/@aghh1504/1-simple-react-todo-list-52186b62976b | |
import React from 'react'; | |
import List from './List'; | |
export default class TodoList extends React.Component { | |
constructor(props) { | |
super(props); | |
this.onChangeList = this.onChangeList.bind(this); | |
this.state = { | |
term : '', | |
listItem: [], | |
message: 'To Do List' | |
} | |
} | |
onChangeList(event) { | |
this.setState({ | |
term: event.target.value | |
}); | |
} | |
onSubmit = (event) => { | |
event.preventDefault() | |
if (this.state.term) { | |
this.setState({ | |
listItem: [...this.state.listItem, this.state.term], | |
term: '', | |
message: 'To Do List' | |
}); | |
} else { | |
let warning = 'you need to fill the field'; | |
this.setState({ | |
message: warning | |
}); | |
} | |
} | |
render() { | |
console.log(...this.state.listItem); | |
return ( | |
<div className='TodoList'> | |
<form className="form" onSubmit={this.onSubmit}> | |
<h1>{this.state.message}</h1> | |
<input type="text" onChange={this.onChangeList} value={this.state.term} /> | |
<button>add</button> | |
</form> | |
<List listItem={this.state.listItem} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment