Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constructor(props) {
- super(props)
- var products = [
- { name: "Motorhead glasses", price: 300, amount: 1 },
- { name: "Judaspriest glasses", price: 499, amount: 1 }
- ]
- this.state = { products: products }
- this.handleMinus = this.handleMinus.bind(this)
- }
- handleMinus(key) {
- var stateCopy = Object.assign({}, this.state);
- stateCopy.products = stateCopy.products.slice();
- stateCopy.products[key] = Object.assign({}, stateCopy.products[key]);
- stateCopy.products[key].amount += 1;
- this.setState({ [this.state.products[key].amount]: stateCopy });
- console.log(this)
- }
Advertisement
Add Comment
Please, Sign In to add comment