MCPcopy Create free account
hub / github.com/coderarmy-notes/mern-stack-course / Product

Function Product

04React/Day10/src/components/Product.jsx:4–20  ·  view source on GitHub ↗
({item})

Source from the content-addressed store, hash-verified

2import { ProductContext } from "../App";
3
4function Product({item}){
5
6 const [addToCart,setAddToCart] = useState(false);
7 const {cartItem,setCartItem} = useContext(ProductContext);
8
9 return(
10 <>
11 <div>
12 <h1>Name: {item.name}</h1>
13 <h2>Price: {item.price}</h2>
14 {
15 addToCart ? <button onClick={()=>{setAddToCart(false), setCartItem(cartItem=>cartItem-1)}}>Remove</button> : <button onClick={()=>{setAddToCart(true), setCartItem(cartItem=>cartItem+1)}}>Add</button>
16 }
17 </div>
18 </>
19 )
20}
21
22export default Product;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected