I used react-navigation 4 in my react native app. I want to use my custom header component for my screen header. My navigator is like this:
const MapTab = createStackNavigator({
MapContainer: {
screen: MapContainer,
navigationOptions: {
header: props =>
<HeaderMap openDrawer={props.navigation.getParam('openDrawer')} />,
},
},
});
As we can see, I need to pass openDrawer function to my <HeaderMap> to open the screen drawer when it pressed. And in my screen, I've set openDrawer function body as navigation param on didMount event.
componentDidMount() {
this.props.navigation.setParams({ openDrawer: this.drawer.openDrawer.bind(this) });
}
And I call it on HeaderMap as below:
<TouchableOpacity onPress={() => this.props.openDrawer()}>
<Icon name="ios-menu" color={colors.white} size={30} />
</TouchableOpacity>
But it doesn't work as expected. I always get error like this on button pressed:
Cannot read property 'getParam' of undefined. I think the props.navigation is undefined when I call getParam.
Any insight of this case? TiA.
