Repository navigation
Expand file tree
/
Copy pathProduct.js
More file actions
46 lines (39 loc) · 1.4 KB
/
Copy pathProduct.js
File metadata and controls
46 lines (39 loc) · 1.4 KB
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
import React from 'react'
import './product.css'
import StarIcon from '@mui/icons-material/Star';
import {useStateValue} from './StateProvider';
function Product({id,title,image,price,rating}) {
const [{basket},dispatch] = useStateValue();
console.log("this is basket"+basket[0]);
const addToBasket = () => {
dispatch({
type : 'ADD_TO_BASKET',
item : {
id:id,
title:title,
image:image,
price:price,
rating:rating,
}
})
}
return (
<div className='product'>
<div className="product_imageDiv">
<img name="Product"src={image} alt="" className='product_image' />
<button onClick={addToBasket}>Add to Basket</button>
</div>
<div className="product_info">
<p>{title}</p>
<p className="product_price">
<small>$</small>
<strong>{price}</strong>
</p>
<div className="product_rating">
{Array(rating).fill().map(()=><StarIcon className='product_rating_star'/>)}
</div>
</div>
</div>
)
}
export default Product