Skip to content
Advertisement

React Navigation – cannot read property ‘navigate’ of undefined

I’ve been trying to get up and running with react navigation but I run into a problem when I try to move navigation items into their own components.

HomeScreen.js

JavaScript

Then in the NavButton component I try to navigate to the new screen.

JavaScript

But I keep getting the error “Cannot read property ‘navigate’ of undefined.

Here is my Router.js file as well.

JavaScript

Advertisement

Answer

If you rename navigate={this.props.navigator} to navigator={this.props.navigation}, it should work because in NavButton you are calling this.props.navigator.navigate.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement