Undefined is not an Object (evaluating '_this.props.navigation.navigate') React Native

Asked

Viewed 4,677 times

1

inserir a descrição da imagem aqui

I have this signOut function that I call through a button, but when I press the exit, where it calls a onPress: () => this.props.navigation.navigate('SignIn') it returns the following error

inserir a descrição da imagem aqui

Does anyone know how I can fix this?

Versions:
React: "16.8.3",
React-Native: "0.59.3",
React-Native-Esture-Handler: "^1.1.0",
React-navigation: "^3.6.0"

  • I didn’t understand the answer marked as right. In which location or at which moment I do this, Sidebar is the custom component ?

1 answer

4


What should be happening is the following, when you use React Navigation, "navigation" is passed as props to the pages you put on the route. However, within this page, the components do not have access to navigation. So if I have on this page a button and use "navigation.navigate" it will work, but if this page has a component, and inside it you try to do the same, it will not work.

To solve this, just create a props and pass the navigation to it. It would be something like this

<Sidebar navigation= {this.props.navigation} />

This way your button should work.

  • Got it! Thank you very much, it worked here!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.