-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathRandomBeer.js
More file actions
31 lines (26 loc) · 948 Bytes
/
RandomBeer.js
File metadata and controls
31 lines (26 loc) · 948 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, { useState, useEffect } from 'react';
const RandomBeer = () => {
const [randomBeer, setRandomBeer] = useState(null);
useEffect(() => {
// Fetch data for a random beer
fetch('https://ih-beers-api2.herokuapp.com/beers/random')
.then((response) => response.json())
.then((data) => setRandomBeer(data))
.catch((error) => console.error('Error fetching random beer details:', error));
}, []);
if (!randomBeer) {
return <div>Loading...</div>;
}
return (
<div>
<h2>{randomBeer.name}</h2>
<img src={randomBeer.image_url} alt={randomBeer.name} style={{ maxWidth: '100px' }} />
<p>{randomBeer.tagline}</p>
<p>First Brewed: {randomBeer.first_brewed}</p>
<p>Attenuation Level: {randomBeer.attenuation_level}</p>
<p>Description: {randomBeer.description}</p>
<p>Contributed by: {randomBeer.contributed_by}</p>
</div>
);
};
export default RandomBeer;