this2.props.openDrawer is not a function(Drawer)
See original GitHub issueI am running sample drawer example. But i am getting error like this: this2.props.openDrawer is not a function. Please give me any suggestion. Thank you. sideBar.js file:
import React, { Component } from 'react';
import {
Text,
} from 'react-native';
import styles from './styles';
import {Content} from 'native-base';
export default class Sidebar extends Component {
render() {
return (
<Content style={{backgroundColor:'#FFFFFF'}}>
<Text>Drawer</Text>
</Content>
);
}
}
module.exports = Sidebar;
Main.js file:
import React, { Component } from 'react';
import {
AppRegistry,
Text
} from 'react-native';
import {Drawer} from 'native-base';
import AppHeader from './appHeader';
import AppBody from './appBody';
import AppFooter from './appFooter';
import Sidebar from './sidebar';
export default class Main extends Component {
closeDrawer = () => {
this.drawer._root.close()
};
openDrawer = () => {
this.drawer._root.open()
};
render() {
return (
<Drawer
ref={(ref) => { this.drawer = ref; }}
content={<Sidebar/>}
onClose={() => this.closeDrawer()} >
<AppHeader
openDrawer={this.openDrawer.bind(this)}
/>
<AppBody/>
</Drawer>
);
}
}
module.exports = Main;
AppHeader.js file:
import React, { Component } from 'react';
import {
Text,
} from 'react-native';
import {Header,Left,Button,Icon,Right,Body,Title} from 'native-base';
export default class AppHeader extends Component {
render() {
return (
<Header>
<Left>
<Button transparent
onPress={()=>this.props.openDrawer()}
>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>SDCC Wallet</Title>
</Body>
<Right>
<Button transparent>
<Icon name='bulb' />
</Button>
</Right>
</Header>
);
}
}
module.exports = AppHeader;
Here is my screenshot:
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Why navigation.closeDrawer is not a function? - Stack Overflow
closeDrawer is not a function . So i try to console.log(this.props); ,i can see openDrawer and closeDrawer under navigation ...
Read more >Drawer navigation
This is documentation for React Navigation 2.x, which is no longer actively maintained. For up-to-date documentation, see the latest version (6.x).
Read more >navigation.opendrawer is not a function v3
_this.props.navigation.opendrawer is not a function. This problem is because the component that you're trying implement is not defined on stackNavigation, and ...
Read more >undefined is not a function (near '...(0,_reactNavigationStack ...
Coding example for the question TypeError: undefined is not a function (near '. ... import { createDrawerNavigator } from '@react-navigation/drawer';.
Read more >undefined is not an object (evaluating 'navigation.navigate')
You can pass it down from a parent which has the prop. function MyBooks(props) { ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You should use onPress={ () =>this.props.navigation.openDrawer() instead of onPress={()=>this.props.openDrawer()} this way working for me
@harikanammi tried your code. It was working fine for me. Attaching a Gif
Gif