Skip to content

Instantly share code, notes, and snippets.

@temon
Created February 1, 2019 09:24
Show Gist options
  • Save temon/85f1bbf7ccd36ae10f1c70b702e06e04 to your computer and use it in GitHub Desktop.
Save temon/85f1bbf7ccd36ae10f1c70b702e06e04 to your computer and use it in GitHub Desktop.
Todo list with react
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