Skip to content

Instantly share code, notes, and snippets.

@basekays
Created June 20, 2018 19:54
Show Gist options
  • Select an option

  • Save basekays/012b1c3ccf6dd2574816de8a73dd42d6 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/012b1c3ccf6dd2574816de8a73dd42d6 to your computer and use it in GitHub Desktop.
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