Skip to content

Instantly share code, notes, and snippets.

@viceversus
Last active January 30, 2016 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viceversus/6e0eaa52409a11a46895 to your computer and use it in GitHub Desktop.
Save viceversus/6e0eaa52409a11a46895 to your computer and use it in GitHub Desktop.
User List HoC
var UserList = React.createClass({
propTypes: {
onSelect: React.PropTypes.func.isRequired,
selection: React.PropTypes.object.isRequired,
},
getInitialState() {
return {
users: [],
};
},
fetchUsers() {
// Hit API, get users, and set to users on state.
// Assume unsharable for... reasons.
},
renderUsers() {
return users.map(function(user) {
return(
<tr>
<td>
<input type="checkbox" onClick={this.props.onSelect(user)} checked={this.props.selection.has(user)} />
</td>
<td>user.name</td>
<td>user.id</td>
<td>user.numberOfBadges</td>
</tr>
);
});
},
render() {
return (
<table>
<thead>
<tr>
<th></th>
<th>"Name"</th>
<th>"ID"</th>
<th>"# of Badges"</th>
</tr>
</thead>
<tbody>
this.renderUsers();
</tbody>
</table>
);
},
});
export default UserList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment