-
Notifications
You must be signed in to change notification settings - Fork 26.2k
/
[id].js
58 lines (51 loc) · 1.21 KB
/
[id].js
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
import fetch from 'node-fetch'
const Person = ({ data, status }) =>
status === 200 ? (
<table>
<thead>
<tr>
<th>Name</th>
<th>Height</th>
<th>Mass</th>
<th>Hair color</th>
<th>Skin color</th>
<th>Eye color</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<tr>
<td>{data.name}</td>
<td>{data.height}</td>
<td>{data.mass}</td>
<td>{data.hair_color}</td>
<td>{data.skin_color}</td>
<td>{data.eye_color}</td>
<td>{data.gender}</td>
</tr>
</tbody>
</table>
) : (
<p>{data.message}</p>
)
export async function getStaticPaths() {
const response = await fetch('http://localhost:3000/api/people')
const data = await response.json()
const paths = data.map(person => ({
params: {
id: person.id,
},
}))
return { paths, fallback: false }
}
export async function getStaticProps({ params }) {
const response = await fetch(`http://localhost:3000/api/people/${params.id}`)
const data = await response.json()
return {
props: {
data,
status: response.status,
},
}
}
export default Person