Created
March 25, 2015 08:34
-
-
Save rippo/05fdb4ab7b2c44eea4f7 to your computer and use it in GitHub Desktop.
React and removing state based on http://stackoverflow.com/questions/29249271/remove-state-from-a-reactjs-component
This file contains hidden or 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 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