I am trying to make an onPress function such that when the menu icon is clicked, my drawer navigation will open. However, I am getting this error: Unhandled JS Exception: Cannot read property 'navigation' of undefined.
Here's my code for HeaderComponent.js
import React from 'react';
import { StyleSheet } from 'react-native';
import { Header, Left, Icon, Body, Title, Right } from 'native-base';
const HeaderComponent = (props) => {
const { menuIconStyle } = styles;
return (
<Header>
<Left>
<Icon
style={menuIconStyle}
name="menu"
onPress={() => this.props.navigation.openDrawer()}
/>
</Left>
<Body>
<Title>{props.headerText}</Title>
</Body>
<Right>
</Right>
</Header>
);
}
export default HeaderComponent;
const styles = StyleSheet.create({
menuIconStyle: {
paddingLeft: 15,
},
});
Would appreciate a solution. Thanks!