0

My buttons:

<div className="ingrBtns"> <button className="ingrBtn" onClick={() => addRemoveIngredient('add','lettuce')}> + </button> <button className="ingrBtn" onClick={() => addRemoveIngredient('remove','lettuce')}> - </button> <div className="price"> &nbsp;&nbsp;&nbsp;${(state.lettuce*0.5).toFixed(2)} </div> </div> 

The function does not work when I click the button. Where is the problem ?

1
  • Did you try adding button type=''button"? Commented Nov 7, 2020 at 11:14

1 Answer 1

2

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"> &nbsp;&nbsp;&nbsp;${(this.state.lettuce*0.5).toFixed(2)}</div> </div> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.