TypeError: navigation.toggleDrawer is not a function. (In 'navigation.toggleDrawer()', 'navigation.toggleDrawer' is undefined)
I've called this function as child component in drawer navigation even though it shows error as toggle drawer could not be able access the drawer menu...If anyone can help me to fix this that would be so helpful
Try use useNavigation
If you use functional component.
import * as React from 'react';
import { Button } from 'react-native';
import { useNavigation } from '@react-navigation/native';
function MyBackButton() {
const navigation = useNavigation();
return (
<Button
title="Back"
onPress={() => {
navigation.goBack();
}}
/>
);
}
If you use class component.
class MyBackButton extends React.Component {
render() {
// Get it from props
const { navigation } = this.props;
}
}
// Wrap and export
export default function(props) {
const navigation = useNavigation();
return <MyBackButton {...props} navigation={navigation} />;
}
The thing is this error occurs because I should have added that particular component in drawer navigation module. After doing that this error has gone.