Skip to content

Instantly share code, notes, and snippets.

@domachine
Last active March 4, 2016 08:36
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 domachine/2469dd2b3613b5310da8 to your computer and use it in GitHub Desktop.
Save domachine/2469dd2b3613b5310da8 to your computer and use it in GitHub Desktop.
class Todos extends Component {
constructor() {
super();
this.state.todos = [{ name: 'Foo' }, { name: 'Bar' }];
}
onChange(todo, name) {
this.setState({
todos: this.state.todos.map(
(t, i) => i === todo ? { name } : t
),
});
}
render() {
return (
<div>
{this.state.todos.map((todo, i) =>
<div className="item">
<input
type="text"
value={todo.name}
onChange={e => this.onChangeTodo(i, e.target.value)}
/>
</div>
)}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment