Skip to content

Instantly share code, notes, and snippets.

@rippo
Created July 1, 2015 10:42
Show Gist options
  • Save rippo/1b8a1bc7d34c927a0091 to your computer and use it in GitHub Desktop.
Save rippo/1b8a1bc7d34c927a0091 to your computer and use it in GitHub Desktop.
two way input box binding with children
var LinkInputs = React.createClass({
getInitialState: function() {
return {input: 0.2};
},
handleChange: function(event) {
console.log('changed parent');
this.setState({ input : event.target.value })
},
render: function() {
return (
<div>
<Input value={this.state.input} onChange={this.handleChange} />
<Input value={this.state.input} onChange={this.handleChange}/>
</div>
);
}
});
var Input = React.createClass({
handleChange: function(event) {
console.log('changed child');
this.props.onChange(event);
},
render : function () {
return (
<div>
<input type="text" value={this.props.value} onChange={this.handleChange} />;
</div>
)
}
})
React.render(<LinkInputs />, document.getElementById('DemoApp'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment