|
|
|
|
|
by haukur
3189 days ago
|
|
It does, you can write this with a Babel preset supporting this feature: class Foo extends Component {
state = {
foo: '',
};
// The arrow function here is what you're looking for.
onChange = ({ target }) => {
this.setState({
// You can of course use `foo` directly as the key if you just have the one input.
[target.name]: target.value,
});
};
render () {
return <input type="text" name="foo" value={this.state.foo.value} onChange={this.onChange} />;
}
}
|
|
Also, your example is not equivalent to either the complaint in the original comment or to the code snippet I quoted
Also: React has been binding event handlers to `this` since forever without presets (update: only in React.creatClass though)