Created
July 1, 2015 10:42
-
-
Save rippo/1b8a1bc7d34c927a0091 to your computer and use it in GitHub Desktop.
two way input box binding with children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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