React read value of button clicked

前端 未结 4 2048
谎友^
谎友^ 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 18:02

    First of all, your buttons don't currently do anything when clicked, so what we're going to need to do is add an onClick to each of your buttons: .

    This will pass the event to handleInput.

    To get the value of the button clicked we can do:

    handleInput(el) {
        console.log(el.target.value);
    }
    

提交回复
热议问题