React read value of button clicked

前端 未结 4 2049
谎友^
谎友^ 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:57

    You are sending and receiving data in a wrong way. First, you need to use onClick={this.handleInput} or onClick={(e) => this.handleInput(e,'value')} instead of onClick={() => this.handleInput('value')} because you are sending 'value' string in function.

    this.handleInput(e, "value")} >

    And then receive in following ways:

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

    You ca check the working demo.

提交回复
热议问题