doc: add addToBasket method

This commit is contained in:
Leon Xu committed 2022-05-05 21:32:15 -07:00
1 parent 47d41ab683
commit 9dc80c75ad
1 file changed
+17 -1
+17 -1
View File
@@ -1,7 +1,23 @@
import React from "react"; import React from "react";
import { useStateValue } from "../redux/StateProvider";
import "./Product.css"; import "./Product.css";
function Product({ title, image, price, rating }) { function Product({ title, image, price, rating }) {
const [{ basket }, dispatch] = useStateValue();
const addToBasket = () => {
dispatch({
type: "ADD_TO_BASKET",
item: {
id: id,
title: title,
image: image,
price: price,
rating: rating,
},
});
};
return ( return (
<section className="product"> <section className="product">
<article className="product__info"> <article className="product__info">
@@ -21,7 +37,7 @@ function Product({ title, image, price, rating }) {
<img src={image} alt="product info" /> <img src={image} alt="product info" />
<button>Add to Basket</button> <button onClick={addToBasket}>Add to Basket</button>
</section> </section>
); );
} }