Skip to content

Instantly share code, notes, and snippets.

@jsrath
Last active November 8, 2018 21:05
Show Gist options
  • Save jsrath/eaeaf01f29b39e857360e2e89ff2d6e0 to your computer and use it in GitHub Desktop.
Save jsrath/eaeaf01f29b39e857360e2e89ff2d6e0 to your computer and use it in GitHub Desktop.
getCartQuantity = () => {
this.getTotalPrice();
const updatedCart = [...this.state.cart];
let quant = [];
updatedCart.forEach(element => {
quant.push(element.quantity);
});
quant = quant.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
this.setState({ totalQuantity: quant });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment