List View: Render Row
Finally, let's define how our rows get rendered in our ListView.
function renderRow(goTo, pokemon, sId, id) {
const POKEMON_STATE = {
title: pokemon.get('name'),
url: pokemon.get('url'),
};
// Some quick parsing to get a bit of extra information for ourselves
const re = /^.*pokemon\/(.+)\/$/;
const matches = re.exec(pokemon.get('url'));
const pokemonID = matches ? matches[1] : null;
const imageUrl = (
pokemonID ? `http://pokeapi.co/media/sprites/pokemon/${ pokemonID }.png` :
null
);
return (
<MediaObject index={ id }
text={ pokemon.get('name') }
imageUrl={ imageUrl }
action={ () => goTo(POKEMON_STATE) } />
);
}Last updated
Was this helpful?