Skip to content

Instantly share code, notes, and snippets.

@Joe1220
Created August 7, 2018 04:04
Show Gist options
  • Save Joe1220/a826fbdb12ce16fc578f2e719876d423 to your computer and use it in GitHub Desktop.
Save Joe1220/a826fbdb12ce16fc578f2e719876d423 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class Item extends Component {
constructor(props) {
super(props);
this.state = {
selectedProduct: {}
};
};
addToCart(image, name, price, id, quantity, checked) {
this.setState({
selectedProduct: {
image: image,
name: name,
price: price,
id: id,
quantity: quantity,
checked: checked
}
}, function() {
this.props.addToCart(this.state.selectedProduct);
})
};
render() {
let image = this.props.image;
let name = this.props.name;
let price = this.props.price;
let id = this.props.id;
let quantity = this.props.productQuantity;
return (
<div className="container">
<img
className="itemImage"
src={this.props.image}
alt={this.props.name}
/>
{this.props.name}
<div className="itemPrice">{this.props.price}</div>
<button color="primary" onClick={this.addToCart.bind(this, image, name, price, id, quantity)}>장바구니에 담기</button>
</div>
);
};
}
export default Item;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment