Guest User

Untitled

a guest
May 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     constructor(props) {
  2.  
  3.         super(props)
  4.  
  5.         var products = [
  6.             { name: "Motorhead glasses", price: 300, amount: 1 },
  7.             { name: "Judaspriest glasses", price: 499, amount: 1 }
  8.         ]
  9.        
  10.         this.state = { products: products }
  11.         this.handleMinus = this.handleMinus.bind(this)
  12.  
  13.     }
  14.  
  15.  
  16.     handleMinus(key) {
  17.         var stateCopy = Object.assign({}, this.state);
  18.         stateCopy.products = stateCopy.products.slice();
  19.         stateCopy.products[key] = Object.assign({}, stateCopy.products[key]);
  20.         stateCopy.products[key].amount += 1;
  21.         this.setState({ [this.state.products[key].amount]: stateCopy });
  22.         console.log(this)
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment