1- import React from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { StyleSheet , Text , View } from 'react-native' ; // React Native API Reference -> https://facebook.github.io/react-native/docs/activityindicator
33import { Header } from './components'
44
5+ const POKEMON_API = `https://pokeapi.co/api/v2/`
6+ const GET_50_POKEMON_PATH = `pokemon?limit=50`
7+
58export default function App ( ) {
9+ const [ pokemonList , setPokemonList ] = useState ( [ ] )
10+ // on componentDidMount grab list of pokemon and set the state to the list
11+ useEffect ( ( ) => {
12+ fetch ( `${ POKEMON_API } ${ GET_50_POKEMON_PATH } ` )
13+ . then ( res => res . json ( ) )
14+ . then ( payload => {
15+ setPokemonList ( payload . results )
16+ } )
17+ . catch ( e => console . log ( e ) )
18+ } , [ ] )
19+ console . log ( pokemonList )
620 return (
721 < View style = { styles . container } >
822 < Header />
23+ < View style = { styles . pokemonList } >
24+ {
25+ pokemonList . map ( pokemon => < View style = { styles . listItem } > < Text style = { styles . listItemText } > { pokemon . name } </ Text > </ View > )
26+ }
27+ </ View >
928 </ View >
1029 ) ;
1130}
@@ -16,6 +35,21 @@ const styles = StyleSheet.create({
1635 backgroundColor : '#f0f0f0' ,
1736 alignItems : 'flex-start' ,
1837 justifyContent : 'center' ,
19- flexDirection : 'row'
38+ flexDirection : 'column'
39+ } ,
40+ pokemonList : {
41+ flex : 1 ,
42+ flexDirection : 'column' ,
43+ width : '100%' ,
44+ } ,
45+ listItem : {
46+ height : 40 ,
47+ alignItems : 'center' ,
48+ justifyContent : 'center' ,
49+ borderBottomWidth : 1 ,
50+ borderBottomColor : 'black' ,
2051 } ,
52+ listItemText : {
53+ fontSize : 20 ,
54+ }
2155} ) ;
0 commit comments