我尝试将操作“addProduct”添加到组件中。但是当我点击它时看到一个错误,帮助我应对,在此先感谢!
我不明白我的错误在哪里(
import { bindActionCreators } from "redux";
import { addProduct } from "../actions/addProduct";
const ProductListItem = ({ product }) => {
return (
<div className="product">
<img className="product_img" src={product.image} />
<p>{product.name}</p>
<p className="bold">$ {product.price}</p>
<button className="add_card" onClick={() => addProduct(product)}>
{" "}
add to cart
</button>
</div>
);
};
export default ({ products = [] }) =>
products.map((product, i) => {
return <ProductListItem key={i} product={product} />;
});
const mapDispatchToProps = dispatch => {
return bindActionCreators({ addProduct }, dispatch);
};
connect(null,
mapDispatchToProps
)(ProductListItem);
[enter image description here][1]
沧海一幻觉
相关分类