react-navigation not working, props is undefined -
i building poc application in react-native , trying implement react-navigation
import {stacknavigator, drawernavigator} 'react-navigation'; export default class homescreen extends react.component { constructor(props) { super(props) this.clicked = this.clicked.bind(this) } static navigationoptions = { drawerlabel: 'home', }; clicked = ()=> { this.props.navigator.navigate('draweropen'); // open drawer } render() { // const {navigate} = this.props.navigation; return ( <scrollview> <view style={styles.container}> <view style={styles.header}> <view style={{width: 50}}> <touchablehighlight onpress={()=> { this.clicked("draweropen") }}> <image source={require('./img/hamburger_icon.png')}/> </touchablehighlight> </view> </view> </view> </scrollview > ) } } now whenever clicking on touchable highlight, clicked function gets called , shows error:
undefined not object (evaluating '_this.props.navigator.navigate') clicked
you try :)
import {stacknavigator, drawernavigator} 'react-navigation'; export default class homescreen extends react.component { static navigationoptions = { drawerlabel: 'home', }; clicked = () => { this.props.navigation.navigate('draweropen'); // open drawer } render() { // const {navigate} = this.props.navigation; return ( <scrollview> <view style={styles.container}> <view style={styles.header}> <view style={{width: 50}}> <touchablehighlight onpress={()=> this.clicked() }> <image source={require('./img/hamburger_icon.png')}/> </touchablehighlight> </view> </view> </view> </scrollview > ) } }
Comments
Post a Comment