-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathSingleBeer.js
More file actions
31 lines (26 loc) · 894 Bytes
/
SingleBeer.js
File metadata and controls
31 lines (26 loc) · 894 Bytes
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
import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import Header from "./Header";
function SingleBeer() {
const { beerId } = useParams();
const [beer, setBeer] = useState(null);
useEffect(() => {
fetch(`https://ih-beers-api2.herokuapp.com/beers/${beerId}`)
.then((response) => response.json())
.then((data) => setBeer(data));
}, [beerId]);
if (!beer) return <p>Loading...</p>;
return (
<div>
<Header />
<img src={beer.image_url} alt={beer.name} width="100" />
<h1>{beer.name}</h1>
<p>{beer.tagline}</p>
<p><strong>First brewed:</strong> {beer.first_brewed}</p>
<p><strong>Attenuation level:</strong> {beer.attenuation_level}</p>
<p>{beer.description}</p>
<p><strong>Contributed by:</strong> {beer.contributed_by}</p>
</div>
);
}
export default SingleBeer;