Skip to content

Commit

Permalink
➕ feat: pokedex
Browse files Browse the repository at this point in the history
  • Loading branch information
Linder Hassinger committed Apr 26, 2024
1 parent 42bd859 commit e857520
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pokedex/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ import pokeSearch from "./assets/poke-search.svg";
function App() {
const [inputValue, setInputValue] = useState("");

const [pokemon, setPokemon] = useState(null);

const handleInputValue = (event) => {
setInputValue(event.target.value);
};

const fetchPokemon = async () => {
const url = `https://pokeapi.co/api/v2/pokemon/${inputValue}`;
const response = await fetch(url);

if (!response.ok) {
alert("Hubo un error");
return;
}

const data = await response.json();

setPokemon(data);
};

return (
<>
<main className="p-6">
Expand All @@ -27,7 +43,10 @@ function App() {
/>
</div>
<div>
<button className="bg-white px-3 py-2 rounded-lg text-primary font-semibold">
<button
onClick={fetchPokemon}
className="bg-white px-3 py-2 rounded-lg text-primary font-semibold"
>
Buscar
</button>
</div>
Expand All @@ -37,7 +56,7 @@ function App() {
<div className="flex items-center justify-center gap-5">
<img
width={150}
src="https://www.pokemon.com/static-assets/content-assets/cms2/img/pokedex/full/001.png"
src={pokemon?.sprites.other["official-artwork"].front_default}
alt=""
/>
<div>
Expand All @@ -48,7 +67,9 @@ function App() {
</div>
</div>
<div className="mt-3 bg-gray-200 flex justify-center items-center h-[60px] rounded-b-lg">
<h2 className="text-center font-semibold text-2xl">Bulbasaur</h2>
<h2 className="text-center font-semibold text-2xl">
{pokemon?.name}
</h2>
</div>
</div>
</div>
Expand Down

0 comments on commit e857520

Please sign in to comment.