Skip to content

Commit e844c8c

Browse files
committed
💻 render list of pokemon
1 parent 61eb810 commit e844c8c

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎App.js‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
import React from 'react';
1+
import React, {useEffect, useState} from 'react';
22
import { StyleSheet, Text, View } from 'react-native'; // React Native API Reference -> https://facebook.github.io/react-native/docs/activityindicator
33
import { Header } from './components'
44

5+
const POKEMON_API = `https://pokeapi.co/api/v2/`
6+
const GET_50_POKEMON_PATH = `pokemon?limit=50`
7+
58
export 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
});

‎components/Header/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function Header() {
77

88
const styles = StyleSheet.create({
99
header: {
10-
flex: 1,
10+
width: '100%',
1111
backgroundColor: '#ee1515',
1212
alignItems: 'center',
1313
justifyContent: 'center',

0 commit comments

Comments
 (0)