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/d8d5cc22af5eac35a041 to your computer and use it in GitHub Desktop.
Save viceversus/d8d5cc22af5eac35a041 to your computer and use it in GitHub Desktop.
Pokemon List No HoC
var PokemonList = React.createClass({
getInitialState() {
return {
pokemon: [],
selection: new Set(),
};
},
fetchPokemon() {
// Hit API, get pokemon, and set to pokemon on state.
// Assume unsharable for... reasons.
},
onSelect(pokemon) {
if(this.state.selection.has(pokemon)) {
this.state.selection.delete(pokemon);
} else {
this.state.selection.add(pokemon);
}
},
renderPokemon() {
return pokemon.map(function(pokemon) {
return(
<tr>
<td>
<input type="checkbox" onClick={this.onSelect(pokemon)} checked={this.state.selection.has(pokemon)} />
</td>
<td>pokemon.name</td>
<td>pokemon.id</td>
<td>pokemon.types</td>
<td>pokemon.favoriteAttack</td>
<td>pokemon.isShiny</td>
</tr>
);
});
},
render() {
return (
<table>
<thead>
<tr>
<th></th>
<th>"Name"</th>
<th>"ID"</th>
<th>"Type(s)"</th>
<th>"Favorite Attack"</th>
<th>"Shiny?"</th>
</tr>
</thead>
<tbody>
this.renderPokemon();
</tbody>
</table>
);
},
});
export default PokemonList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment