Skip to content

Instantly share code, notes, and snippets.

@rippo
Created March 25, 2015 08:34
Show Gist options
  • Save rippo/05fdb4ab7b2c44eea4f7 to your computer and use it in GitHub Desktop.
Save rippo/05fdb4ab7b2c44eea4f7 to your computer and use it in GitHub Desktop.
var MachineInfo = React.createClass({
getInitialState: function() {
return {
data: []
};
},
componentDidMount: function() {
$.get(this.props.source, function(result) {
this.setState({
data: result
});
}.bind(this));
},
render: function() {
return <MachineInfoHeader data={this.state.data} />
}
});
var MachineInfoHeader = React.createClass({
render: function() {
var createMachineInfoItems = function(info) {
return <MachineInfoItem info={info} />
};
return <div>{this.props.data.map(createMachineInfoItems)}</div>
}
});
var MachineInfoItem = React.createClass({
render: function() {
return <p>
{this.props.info.Id}
{this.props.info.Key}
{this.props.info.Value}
</p>
}
});
React.render(
<MachineInfo source="/ajax/namevalues/2" />,
document.getElementById('reactdiv')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment