React input onChange won't fire

前端 未结 4 1532
我在风中等你
我在风中等你 2020-12-16 18:01

I currently have this simple react app and I cannot get these onchange events to fire for the life of me.

var BlogForm = React.createClass({
getInitialState:         


        
4条回答
  •  遥遥无期
    2020-12-16 18:03

    when you use :

    onChange={this.changeTitle (this)}
    

    react will call mentioned function automatically. you need to call the function like this:

    onChange={this.changeTitle}
    

    and also change your mentioned function to arrow function, otherwise you cant use "this" keyword in your function. in none arrow function "this" keyword is not object of your function so you cant access to your variables. if you need to pass arguments to your function you should use other methods like bind()

提交回复
热议问题