Last active
January 30, 2016 00:35
-
-
Save viceversus/d8d5cc22af5eac35a041 to your computer and use it in GitHub Desktop.
Pokemon List No 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 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