Skip to content

Instantly share code, notes, and snippets.

@heyjohnmurray
Created November 23, 2015 06:51
Show Gist options
  • Save heyjohnmurray/4e1a6f76e809bdc10da5 to your computer and use it in GitHub Desktop.
Save heyjohnmurray/4e1a6f76e809bdc10da5 to your computer and use it in GitHub Desktop.
We can create dynamic component data from sets of data
/** @jsx React.DOM */
var React = require('react');
var PersonTable = React.createClass({
getInitialState: function(){
return {
data: [
{id: 1, fname: 'John', lname: 'Murray'},
{id: 2, fname: 'Wyatt', lname: 'Murray'},
{id: 3, fname: 'McKenzie', lname: 'Murray'}
],
};
},
render: function(){
// the only thing I don't understand about all this is how 'person' gets first and last name. how is it create?!
var rows = this.state.data.map(function(person, i){
return <PersonRow data={person} key={i} />;
});
return <table>{rows}</table>;
},
});
var PersonRow = React.createClass({
render: function(){
return (
<tr>
<td>{this.props.data.id}</td>
<td>{this.props.data.fname}</td>
<td>{this.props.data.lname}</td>
</tr>
);
},
});
module.exports = PersonTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment