Akshay
Akshay

Reputation: 6142

React Native, Android, undefined is not an object (evaluating 'this.props.navigator.push')

I'm trying to navigate from login screen to home screen on submit buttonclick... Following is my fucnction for navigation

  onsubmitButtonPress(event)
{
  if(User != null && password != null){
    if(User != '' && password != ''){
    if (User == password){
      ToastAndroid.show('Login Successful', ToastAndroid.SHORT);
      this.props.navigator.push({
              title: 'Home',
              component: HomeScreen,
            });
    }else{
      ToastAndroid.show('Login Failed', ToastAndroid.SHORT);
    }
  }else{
    ToastAndroid.show('Fill details', ToastAndroid.SHORT);
  }
  }else{
    ToastAndroid.show('Fill details', ToastAndroid.SHORT);
  }
}

But I'm getting this error.Can anybody help me out..

Upvotes: 0

Views: 2106

Answers (1)

Adam Terlson
Adam Terlson

Reputation: 12730

The problem is likely how you're calling onsubmitButtonPress. Change where you set it on your component from this:

someProp={this.onsubmitButtonPress}

to this:

someProp={(e) => this.onsubmitButtonPress(e)}

The issue being that this is not defined.

If it's NOT that, then it's likely that you're never defining this.props.navigator. Put a breakpoint (or a console.log) in your function there to log the value of this.props and check if it exists, and if it does, if this.props.navigator is defined on it.

Upvotes: 1

Related Questions