'TypeError: navigation.toggleDrawer is not a function. (In 'navigation.toggleDrawer()', 'navigation.toggleDrawer' is undefined) this error occured

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



Solution 1:[1]

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} />;
   }

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 meowww
Solution 2 Jey Prakash