0

calling this.props.navigation.dispatch(resetAction); inside componentWillMount() works fine for me, but if I try this code

componentWillMount(){
    Keychain
    .getGenericPassword()
    .then(function(credentials) {
         this.props.navigation.dispatch(resetAction);
    })
}

I get an error telling me that this.props.navigation is undefined. I suppose that the problem is that I am calling it inside .then. Do you know how can I solve this?

A.A Noman
  • 5,244
  • 9
  • 24
  • 46
j.doe
  • 4,559
  • 6
  • 20
  • 31

1 Answers1

0

you just change the scope of this

try this

componentWillMount(){
Keychain
  .getGenericPassword()
  .then((credentials)=>{
this.props.navigation.dispatch(resetAction);
});

or else use extra val for this like

var _self = this;
Jigar
  • 1,314
  • 9
  • 19