score:1

Accepted answer

you have options when trying to correctly bind a method to an inline callback:

also: you're assumption that omitting the mapdispatchtoprops results in the dispatch being mapped to the props as this.props.dispatch is correct.


use the arrow function:

onpress={this.handlelogin(dispatch)}

to:

onpress={() => this.handlelogin}

// this is lexcially bound inside an arrow function, yay!


use bind in the constructor function:

constructor(props){
  super(props)

  this.handlelogin = this.handlelogin.bind(this);
}

use bind within the inline callback:

onpress={this.handlelogin.bind(this);}


Related Query

More Query from same tag