Created
October 14, 2022 19:52
-
-
Save nologyRob/15378300ed6f129555319a61f2264b12 to your computer and use it in GitHub Desktop.
Pokemon App
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 React, {useState,useEffect} from 'react' | |
import './App.css'; | |
function App() { | |
const [pokemon, setPokemon] = useState([]) | |
useEffect(()=>{ | |
getPokemon() | |
},[]) | |
const showPokemon = () => { | |
console.log(pokemon) | |
} | |
const getPokemon = async () =>{ | |
const newPokemon = [...pokemon] | |
for (let i = 1; i < 1000; i++) { | |
const res = await fetch(`https://pokeapi.co/api/v2/pokemon/${i}`) | |
const jres = await res.json() | |
const pokemonObj = { | |
id: jres.id, | |
name: jres.name, | |
image: [jres.sprites], | |
baseExp: [jres.base_experience] | |
} | |
newPokemon.push(pokemonObj) | |
setPokemon(newPokemon) | |
} | |
} | |
return ( | |
<div className="App"> | |
<button onClick={showPokemon}>Show Pokemon</button> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment