Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const INGREDIENT_PRICES = {
- salad: 5,
- cheese: 10,
- meat: 20,
- bacon: 10
- state ={
- ingredients: {
- salad: 0,
- bacon : 0,
- cheese: 0,
- meat: 0
- },
- totalPrice: 30,
- purchaseble: false
- }
- addIngredientHandler = (type) => {
- const oldCount = this.state.ingredients[type];
- const updatedCount = oldCount +1;
- const updatedIngredients = {
- ...this.state.ingredients
- };
- updatedIngredients[type] = updatedCount;
- const priceAddition = INGREDIENT_PRICES[type];
- const newPrice = this.state.totalPrice + priceAddition
- this.setState({totalPrice: newPrice, ingredients: updatedIngredients})
- this.updatePurchaseState();
- }
Add Comment
Please, Sign In to add comment