If I understood correctly I hope this can help you:
MailProduct.tsx
import React,{useState} from 'react'
import Toppings from "./ToppingsName";
export default function MainProduct() {
const [quantity, setQuantity] = useState(1);
const quantityIncrease = () => {setQuantity(quantity + 1);}
const quantityDecrease = () => {setQuantity(quantity - 1);}
const [includedInList, setIncludedInList] = useState([])
var pizzaPrize = (185.0 * quantity);
const [toppings, setToppings] = useState({
mushroom: {
prize: 10,
tick: true
},
onions: 7,
blackOlives: 9.5,
bacon: 12
})
var totalPizzaPrize = pizzaPrize;
console.log('list',includedInList)
return (
<>
<div className="container">
<div className="product-heading">Pepperoni</div>
{/* <label className="quantity-label">Quantity</label> */}
<div className="count-cart">
<div className="pizza-count">
<div className="pc-minus" onClick={quantityDecrease}>
-
</div>
<div className="pc-count">{quantity}</div>
<div className="pc-plus" onClick={quantityIncrease}>
+
</div>
</div>
<div className="add-to-cart">Add to Cart</div>
<div className="pizza-prize">
Rs {pizzaPrize.toFixed(2)}
</div>
</div>
<div className="pizza-toppings">
{/* <label className="toppings-label">Toppings</label> */}
<Toppings name={`Mushroom`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.mushroom.prize).toFixed(2)} />
<Toppings name={`Onions`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.onions).toFixed(2)} />
<Toppings name={`Black olives`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.blackOlives).toFixed(2)} />
<Toppings name={`Bacon`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.bacon).toFixed(2)} />
</div>
<div className="total-pizza-prize">Total : Rs {(totalPizzaPrize).toFixed(2)}</div>
</div>
</>
);
}
Topplings Name:
import React,{useState} from 'react'
import Toppings from "./ToppingsName";
export default function MainProduct() {
const [quantity, setQuantity] = useState(1);
const quantityIncrease = () => {setQuantity(quantity + 1);}
const quantityDecrease = () => {setQuantity(quantity - 1);}
const [includedInList, setIncludedInList] = useState([])
var pizzaPrize = (185.0 * quantity);
const [toppings, setToppings] = useState({
mushroom: {
prize: 10,
tick: true
},
onions: 7,
blackOlives: 9.5,
bacon: 12
})
var totalPizzaPrize = pizzaPrize;
return (
<>
<div className="container">
<div className="product-heading">Pepperoni</div>
{/* <label className="quantity-label">Quantity</label> */}
<div className="count-cart">
<div className="pizza-count">
<div className="pc-minus" onClick={quantityDecrease}>
-
</div>
<div className="pc-count">{quantity}</div>
<div className="pc-plus" onClick={quantityIncrease}>
+
</div>
</div>
<div className="add-to-cart">Add to Cart</div>
<div className="pizza-prize">
Rs {pizzaPrize.toFixed(2)}
</div>
</div>
<div className="pizza-toppings">
{/* <label className="toppings-label">Toppings</label> */}
<Toppings name={`Mushroom`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.mushroom.prize).toFixed(2)} />
<Toppings name={`Onions`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.onions).toFixed(2)} />
<Toppings name={`Black olives`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.blackOlives).toFixed(2)} />
<Toppings name={`Bacon`} includedInList={includedInList} setIncludedInList={setIncludedInList} prize={(toppings.bacon).toFixed(2)} />
</div>
<div className="total-pizza-prize">Total : Rs {(totalPizzaPrize).toFixed(2)}</div>
<p>{JSON.stringify(includedInList)}</p>
</div>
</>
);
}
It's not a completed solution but you can do the maths on includedInList to calculate the final price.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…