My buttons:
<div className="ingrBtns">
<button className="ingrBtn"
onClick={() => addRemoveIngredient('add','lettuce')}>
+
</button>
<button className="ingrBtn"
onClick={() => addRemoveIngredient('remove','lettuce')}>
-
</button>
<div className="price">
${(state.lettuce*0.5).toFixed(2)}
</div>
</div>
The function does not work when I click the button. Where is the problem ?
You must use the keyword "this"
<div className="ingrBtns">
<button className="ingrBtn" onClick={() => this.addRemoveIngredient('add','lettuce')}>+</button>
<button className="ingrBtn" onClick={() => this.addRemoveIngredient('remove','lettuce')}>-</button>
<div className="fiyat"> ${(this.state.lettuce*0.5).toFixed(2)}</div>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.