Created
July 13, 2021 19:59
-
-
Save Souvikns/aef871d6044de841b8fc420da1a98d96 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 "./styles.css"; | |
import { usePokemon } from "./hook"; | |
export default function App() { | |
let pokemons = usePokemon(); | |
return ( | |
<div> | |
<h1>Hello CodeSandbox</h1> | |
<h2>Start editing to see some magic happen!</h2> | |
<table> | |
<tr> | |
<th>ID</th> | |
<th>Sprite</th> | |
<th>Name</th> | |
</tr> | |
{pokemons.map((el) => ( | |
<tr> | |
<td>{el.id}</td> | |
<td> | |
<img src={el.sprite} alt={el.name} /> | |
</td> | |
<td>{el.name}</td> | |
</tr> | |
))} | |
</table> | |
</div> | |
); | |
} |
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 { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
export const usePokemon = () => { | |
let [pokemons, setPokemons] = useState([]); | |
const fetchPokemons = async () => { | |
try { | |
let { data } = await Axios({ | |
url: "https://klifu.deta.dev/pokemons", | |
method: "GET" | |
}); | |
setPokemons(data); | |
} catch (error) { | |
console.log(error); | |
} | |
}; | |
useEffect(() => { | |
fetchPokemons(); | |
}); | |
return pokemons; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment