Undefined is not an object evaluating this.state/this.props

前端 未结 4 938
心在旅途
心在旅途 2021-01-28 16:20

How do I bind a function outside of scope in React Native? I\'m getting the errors:

undefined is not an object evaluating this.state   

&

4条回答
  •  野性不改
    2021-01-28 16:25

    not sure if this is the problem, but I think is code is wrong, and may be potentially causing your issue.

    
      
      View Video
      
    
    

    specifically this line onPress={this._buttonPress().bind(this)}> you are invoking the function and binding it at the same time.

    The correct way to do this would be so

    onPress={this._buttonPress.bind(this)}>
    

    this way the function will be called only onPress.

提交回复
热议问题