Last active
January 30, 2016 00:35
-
-
Save viceversus/6e0eaa52409a11a46895 to your computer and use it in GitHub Desktop.
User List HoC
This file contains 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 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