Getting undefined is not an object evaluating _this.props.navigation
Perhaps I'm overlooking something, but it just looks like a simple Javascript error. You're destructing your props in your pure component MyNavScreen
:
const MyNavScreen = ({ navigation }) => (
This means that you don't have access to this.props
. You just have access to the destructured prop navigation
. Hence the reason for the undefined error as this really is undefined:
<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>
If you change it instead to use navigation
directly, it should work:
<TouchableHighlight onPress={() => navigation.navigate('DrawerOpen')}>
On mainScreen
, you are fine because it's not a pure component with destructured arguments. So you still have access to this.props
in render()
.
You should brush up on destructing if this is causing you trouble.
If you are using navigation in child component don't forget to send navigation in props to child
<ChildComponent navigation={this.props.navigation}/>
Access in child component like this
props.navigation.navigate("ScreenName")