-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client' | ||
import React, { useState, useEffect, ReactElement } from 'react' | ||
import Link from 'next/link' | ||
|
||
interface Props { | ||
params: { slug: string } | ||
} | ||
|
||
export default function PokemonProfile ({ params: { slug } }: Props): ReactElement { | ||
const [pokemon, setPokemon] = useState<string[]>([]) | ||
|
||
useEffect(function fetchPokemon () { | ||
void fetch(`https://pokeapi.co/api/v2/pokemon/${slug}`) | ||
.then(async results => await results.json()) | ||
.then(({ sprites }: { sprites: { back_default: string } }) => { | ||
const pokemonAvatars = Object.values(sprites).filter(image => typeof image === 'string').reverse() | ||
|
||
setPokemon(pokemonAvatars) | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<Link href="/">< Back</Link> | ||
<br /> | ||
<br /> | ||
<div style={{ textTransform: 'capitalize' }}>{slug}</div> | ||
{pokemon.map(image => ( | ||
<img key={image} src={image} alt="pokemon image" /> | ||
))} | ||
</> | ||
) | ||
} |
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