-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokemonDetail.js
More file actions
85 lines (78 loc) · 2.65 KB
/
Copy pathPokemonDetail.js
File metadata and controls
85 lines (78 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useEffect, useState } from "react";
import { Badge, Tr, Td, HStack, VStack, Heading, Box, TableContainer, Tab } from "@chakra-ui/react";
import { Image } from "@chakra-ui/react";
import { useParams } from "react-router-dom";
import { Table } from "@chakra-ui/react";
import { Tbody } from "@chakra-ui/react";
const Detail = ({ pokemon }) => {
return (
<Box>
{pokemon && (
<Box role="pokemon-detail">
{/* TODO: display pokemon name here */}
<Heading>{pokemon.name}</Heading>
{/* TODO: answer here */}
{/* TODO: display pokemon type here */}
{pokemon.types.map((type) => (
<Badge key={type.type.name} marginLeft={1}>{type.type.name}</Badge>
))}
{/* TODO: answer here */}
<HStack>
<Image src={pokemon.sprites.front_default} />
<Image src={pokemon.sprites.back_default} />
<Image src={pokemon.sprites.front_shiny} />
<Image src={pokemon.sprites.back_shiny} />
</HStack>
{/* TODO: render pokemon height, weight, base_experience, abilities, and stats here */}
<TableContainer>
<Table variant='simple'>
<Tbody>
<Tr>
<Td>Height</Td>
<Td>{pokemon.height}</Td>
</Tr>
<Tr>
<Td>Weight</Td>
<Td>{pokemon.weight}</Td>
</Tr>
<Tr>
<Td>Base Experience</Td>
<Td>{pokemon.base_experience}</Td>
</Tr>
<Tr>
<Td>Abilities</Td>
<Td>{pokemon.abilities.map((ability) => <p>{ability.ability.name}</p>)}</Td>
</Tr>
<Tr>
<Td>Stats</Td>
<Td>
{pokemon.stats.map((stat) => (
<p>{stat.stat.name}: {stat.base_stat}</p>
))}
</Td>
</Tr>
</Tbody>
</Table>
</TableContainer>
{/* TODO: answer here */}
</Box>
)}
</Box>
);
};
const Page = () => {
//TODO: read pokemonId from parameter
const { pokemonId } = useParams(); // TODO: replace this
const [pokemon, setPokemon] = useState(null);
const fetchPokemon = async (id) => {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}/`);
const data = await response.json();
setPokemon(data);
};
useEffect(() => {
// TODO: answer here
fetchPokemon(pokemonId);
}, [pokemonId]);
return <Detail pokemon={pokemon} />;
};
export default Page;