Created
February 1, 2019 09:24
-
-
Save temon/85f1bbf7ccd36ae10f1c70b702e06e04 to your computer and use it in GitHub Desktop.
Todo list with react
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
import React, { Component } from 'react'; | |
import './App.css'; | |
class App extends Component { | |
state = { | |
inputText : '', | |
data: [] | |
}; | |
onInputChanges = (event) => { | |
this.setState({ | |
inputText: event.target.value | |
}) | |
}; | |
onButtonClick = () => { | |
this.setState({ | |
data: [ | |
...this.state.data, | |
this.state.inputText, | |
], | |
inputText: '' | |
}) | |
}; | |
render() { | |
return ( | |
<div className="App"> | |
<div> | |
<input | |
type="text" | |
placeholder="insert todo list" | |
value={this.state.inputText} | |
onChange={this.onInputChanges} | |
/> | |
<button type="submit" onClick={this.onButtonClick}>Submit</button> | |
</div> | |
<div> | |
{this.state.data.length > 0 && ( | |
<ul> | |
{this.state.data.map((list, key) => { | |
return ( | |
<li key={key}>{list}</li> | |
); | |
})} | |
</ul> | |
)} | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment