-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartItem.js
More file actions
81 lines (70 loc) · 2.63 KB
/
CartItem.js
File metadata and controls
81 lines (70 loc) · 2.63 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react'
function CartItem(props) {
//now we dont need any of this constructor or functions, coz now we gonna change state of cart, not cartItem
/* constructor(){
super()
this.state={
title:'PHONE',
cost:999,
qty:1,
img:''
}
} */
//so we're doing this instead of the bind thing, which is kinda not req if you use arrow function
//add=()=>{
//now to change the state, we need to use setState, and there 2 ways
/* this.setState({
qty:this.state.qty+1
}) */
//that was the first form to do it, use this object way if the prevState isnt req
/* use this method if the prevState is not required, also note that we're returning an object in this
function */
/* this.setState((prevState)=>{
return{
qty:prevState.qty+1
}
})
}
subtract=()=>{
this.setState((prevState)=>{
return{
qty:prevState.qty-1
}
})
} */
const product=props.product
const {title,price,qty}=product
return (
<div className='cart-item'>
<div className='left-half'>
<img className='item-pic' />
</div>
<div className='right-half'>
<div className="item-props" style={{fontSize:30}}>{title}</div>
<div className="item-props" style={{color:"#777"}}>PRICE:{price} </div>
<div className="item-props" style={{color:"#777"}}>QTY:{qty} </div>
<div className='cart-actions'>
<img
alt="plus"
className='action-item'
src="https://cdn-icons-png.flaticon.com/128/992/992651.png"
onClick={()=>props.functions.IncreaseQuantity(product)}
/>
<img
alt="minus"
className='action-item'
src="https://cdn-icons-png.flaticon.com/128/992/992683.png"
onClick={()=>props.functions.DecreaseQuantity(product)}
/>
<img
alt="bin"
className='action-item'
src="https://cdn-icons.flaticon.com/png/128/484/premium/484662.png?token=exp=1650188207~hmac=bfef6e76862cd1aef8905905e3919e5c"
onClick={()=>props.functions.DeleteItem(product.id)}
/>
</div>
</div>
</div>
)
}
export default CartItem