-
-
Save ankitamasand/1262135ffb8cd9c9306626d6809b1ec1 to your computer and use it in GitHub Desktop.
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
import React, { Component } from 'react'; | |
import { PokemonListModel } from './pokemon-model'; | |
interface PokemonProps {} | |
interface PokemonState { | |
pokemonList: PokemonListModel | null; | |
} | |
class PokemonList extends Component<PokemonProps, PokemonState> { | |
constructor (props) { | |
super(props); | |
this.state = { | |
pokemonList: null | |
} | |
} | |
getPokemonList = () => { | |
fetch ('https://pokeapi.co/api/v2/pokemon/?limit=50') | |
.then (response => { | |
return response.json(); | |
}) | |
.then (response => { | |
this.setState({ pokemonList: response }); | |
}) | |
} | |
render () { | |
let { pokemonList } = this.state; | |
return ( | |
<div className='pokemon-list'> | |
{ | |
pokemonList && pokemonList.results.map (pokemon => { | |
return ( | |
<div className='row' key={pokemon.name}> | |
<span>{pokemon.name}</span> | |
</div> | |
) | |
}) | |
} | |
</div> | |
) | |
} | |
componentDidMount () { | |
this.getPokemonList() | |
} | |
} | |
export default PokemonList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment