1

I am trying to navigate from one component to another screen in ReactNative. But getting following

Possible Unhandled Promise Rejection, TypeError: undefined is not an object (evaluating 'navigation.navigate')]

Following is my code in which i wait to fetch place details and then want to navigate to another screen with those details.

constructor(props) {
super(props)
this.state = {status: 'initial'}
this._handlePress = this._handlePress.bind(this);
 }



_handlePress = async ({navigation}) => {
const res = await this.props.fetchDetails(this.props.place_id)
console.log('result', res.geometry.location.lat)
navigation.navigate("Home", {selectedLocation: res.geometry.location});

}

I have tried this.props.navigation.navigate() as well but couldn't fix this.

I get following:

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_this.props.navigation.navigate')]

Following is the full component code: Pastebin Link

1 Answer 1

1

use withNavigation method, as you have already imported it from react-navigation.

export default withNavigation(LocationItem);

If not resolved then pass navigation as a prop from where it has been used.

<LocationItem navigation={this.props.navigation}/>
Sign up to request clarification or add additional context in comments.

2 Comments

although I just assumed that you are having issues with navigation, because you have not mentioned.
I will need some more info, are you using this class as component to other Classes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.