Skip to content

Instantly share code, notes, and snippets.

@nologyRob
Created October 14, 2022 19:52
Show Gist options
  • Save nologyRob/15378300ed6f129555319a61f2264b12 to your computer and use it in GitHub Desktop.
Save nologyRob/15378300ed6f129555319a61f2264b12 to your computer and use it in GitHub Desktop.
Pokemon App
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