forked from vercel/next.js
/
[id].js
45 lines (41 loc) · 969 Bytes
/
[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
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 getServerSideProps({ 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