Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created June 7, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofmint/ff855e59e708d7d2bf602ca8636988ea to your computer and use it in GitHub Desktop.
Save goofmint/ff855e59e708d7d2bf602ca8636988ea to your computer and use it in GitHub Desktop.
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e => {
this.setState({ text: e.target.value });
};
addTodo = () => {
let { todos, text } = this.state;
todos = todos.concat({ text });
this.setState({ todos, text: '' });
};
render({ }, { todos, text }) {
return (
<form onSubmit={this.addTodo} action="javascript:">
<input value={text} onInput={this.setText} />
<button type="submit">Add</button>
<ul>
{ todos.map( todo => (
<li>{todo.text}</li>
)) }
</ul>
</form>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment