Skip to content

Instantly share code, notes, and snippets.

@heyjohnmurray
Last active November 19, 2015 23:08
Show Gist options
  • Save heyjohnmurray/b194fab3618d3607c1c4 to your computer and use it in GitHub Desktop.
Save heyjohnmurray/b194fab3618d3607c1c4 to your computer and use it in GitHub Desktop.
This shows how a widget can call another widget
var App = React.createClass({
getInitialState: function() {
return {
text: 'this is initial state text',
};
},
// update is a custom function we've created
update: function(e) {
this.setState({text: e.target.value});
},
render: function() {
return (
<div>
<Widget text={this.state.text} update={this.update} />
<Widget text={this.state.text} update={this.update} />
</div>
);
},
});
var Widget = React.createClass({
render: function() {
return (
<div>
<input type='text' onChange={this.props.update} />
<h1>{this.props.text}</h1>
</div>
);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment