undefined is not an object (Evaluating this.props.navigation)

时间:2017-12-18 06:36:36

标签: javascript reactjs react-native ecmascript-6

I'm trying to keep touchable opacity at top right in navigation bar, For onPress of touchable opacity. I want to take the user to home page.

constructor(props) {
    super(props);
    this.state = {
        stAccntList: [],
        stUserAccountNo: '',
        stCustNo: '',
        resp: '',
    };


}
static navigationOptions = {
    //  title: 'myacc',
    title: 'My Accounts',
    headerRight: <TouchableHighlight onPress={() => {
        this.props.navigation.navigate('home');
    }}>
        <Image style={{ marginRight: 20 }} source={require('../../../resources/toolbar/home_inactive.png')} />
    </TouchableHighlight>,
    headerTintColor: 'white',
    headerStyle: {
        backgroundColor: colors.themeColor,
        //  top: 30
    }
}

It's throwing red screen with above error. Please let me know where I'm going wrong.

1 个答案:

答案 0 :(得分:0)

Try this it is work :)

         static navigationOptions = ({navigation}) => ({
                title: 'My Accounts',
                headerRight: <TouchableHighlight onPress={() => {
                    navigation.navigate('home');
                }}>
                <Image style={{ marginRight: 20, height: 30, width: 30 }}
source={{ uri:https://media.freepik.com/accounts/img/badges/downloads_gold.png' 
    }} />
                </TouchableHighlight>,
                headerTintColor: 'white',
                headerStyle: {
                    backgroundColor: colors.themeColor,
                    //  top: 30
                }
            })