-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathProductDetails.jsx
More file actions
35 lines (30 loc) · 887 Bytes
/
ProductDetails.jsx
File metadata and controls
35 lines (30 loc) · 887 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
32
33
34
35
import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import ProductDetailsCard from '../Components/ProductDetailsCard';
import { getProductBySlug } from '../api';
const ProductDetails = () => {
const [product, setProduct] = useState([]);
const navigate = useNavigate();
const { slug } = useParams();
useEffect(() => {
const fetchProduct = async () => {
const { cocktail } = await getProductBySlug(slug);
setProduct(cocktail);
};
fetchProduct();
}, [slug]);
return (
<div className="container">
<button className="btn" onClick={() => navigate(-1)}>
Go Back
</button>
<div>
<div className="title">
<h1>{product.name}</h1>
</div>
<ProductDetailsCard product={product} />
</div>
</div>
);
};
export default ProductDetails;