React read value of button clicked

前端 未结 4 2051
谎友^
谎友^ 2020-12-31 17:20

Sorry if this topic it\'s probably a copy of another one, but i don\'t understand what i\'m doing wrong with my code + i\'m really new to react. I tried several solutions bu

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 17:55

    You could use the event object. Something like:

        handleInput = e => {
          const buttonValue = e.target.value;
          console.log(buttonValue);
          //some logic
    }
    

    And then you could add the method on the onClick event, passing the event object as well.

       onClick = {this.handleInput}
    

提交回复
热议问题