React: trigger onChange if input value is changing by state?

后端 未结 9 1910
我在风中等你
我在风中等你 2020-11-30 04:34

Edit: I don\'t want to call handleChange only if the button has been clicked. It has nothing to do with handleClick. I gave an example in the @shubhakhatri

9条回答
  •  迷失自我
    2020-11-30 04:54

    I think you should change that like so:

     {this.handleChange(e)}}/>
    

    That is in principle the same as onClick={this.handleClick.bind(this)} as you did on the button.

    So if you want to call handleChange() when the button is clicked, than:

    
    

    or

    handleClick () {
      this.setState({value: 'another random text'});
      this.handleChange();
    }
    

提交回复
热议问题