Last active
May 17, 2021 16:52
-
-
Save TRomesh/68282ccaa3f78ccb0695b09d1a2aa16e to your computer and use it in GitHub Desktop.
List Component for Pokémon application with Hookstate
This file contains hidden or 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
import useGlobalState from "../store" | |
import { List, ListItem, ListIcon, ListContent, ListHeader, ListDescription, Segment } from 'semantic-ui-react' | |
function Row({ id, name, power, description, selectPokemon, deletePokemon }) { | |
return ( | |
<ListItem> | |
<ListIcon name="trash alternate outline" onClick={() => deletePokemon(id)}></ListIcon> | |
<ListIcon name="edit outline" onClick={() => selectPokemon({ id, name, power, description })}></ListIcon> | |
<ListContent> | |
<ListHeader as="h3">{name}</ListHeader> | |
<ListHeader as="h5">{power}</ListHeader> | |
<ListDescription>{description}</ListDescription> | |
</ListContent> | |
</ListItem> | |
) | |
} | |
function PokemonList() { | |
const state = useGlobalState(); | |
const deletePokemon = (id) => { | |
state.deletePokemon(id); | |
} | |
const selectPokemon = (pokemon) => { | |
state.selectPokemon(pokemon); | |
} | |
return ( | |
<Segment> | |
<List> | |
{ | |
state.get().pokemons.map((pokemon) => { | |
return <Row key={pokemon.id} | |
id={pokemon.id} | |
name={pokemon.name} | |
power={pokemon.power} | |
selectPokemon={selectPokemon} | |
deletePokemon={deletePokemon} | |
description={pokemon.description}></Row> | |
})} | |
</List> | |
</Segment> | |
) | |
} | |
export default PokemonList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment