Trying to change all the components into es6

后端 未结 2 744
感情败类
感情败类 2021-01-27 07:08
  • I am trying to change all the components into es6
  • I did for two but not sure how to do for the third one.
  • can you tell me how to change it?
  • p

2条回答
  •  感情败类
    2021-01-27 07:57

    this is unavailable in that method.. when you call this.changeContent on line 60 change it to this.changeContent.bind(this). That will bind your component instance to the method.

    you can also do this in a constructor if you want to by adding: this.changeContent = this.changeContent.bind(this) inside the constructor below super(props), then you can use the method as you have it

    Can read more about bind here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

提交回复
热议问题