Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native react native:undefined不是对象(评估';"this2.props.navigation.navigate';)_React Native_React Navigation - Fatal编程技术网

React native react native:undefined不是对象(评估';"this2.props.navigation.navigate';)

React native react native:undefined不是对象(评估';"this2.props.navigation.navigate';),react-native,react-navigation,React Native,React Navigation,我是react native的新手,我正在尝试使用StackNavigator,但它不起作用 我试图调用一个组件,并在您单击按钮时渲染它。 但我得到了一个错误: undefined不是对象(计算'\u this2.props.navigation.navigate') 这是我的主要组成部分: export default class Home extends Component<{}> { constructor(props) { super(props);

我是react native的新手,我正在尝试使用StackNavigator,但它不起作用 我试图调用一个组件,并在您单击按钮时渲染它。 但我得到了一个错误:
undefined不是对象(计算'\u this2.props.navigation.navigate')

这是我的主要组成部分:

export default class Home extends Component<{}> {

    constructor(props) {
        super(props);
        this.email = null;
        this.amount = null;
        this.device = null;
    }

    render() {
        return (
            <ScrollView style={styles.styleSV}>
                <Text
                    style={styles.styleLogin}>
                    Login
                </Text>
                <View style={styles.styleForm}/>
                <TextInput placeholder='email' onChangeText={(text) => this.email }/>
                <TextInput placeholder='amount' onChangeText={(text) => this.amount }/>
                <TextInput placeholder='device' onChangeText={(text) => this.device }/>
                <View style={styles.styleButtonSignup}/>
                <Button
                    onPress={() =>
                        this.props.navigation.navigate('PaypalPayment', { email: this.email })
                    }
                    title='Next'
                />
            </ScrollView>
        );
    }

}

const NavigationScreen = StackNavigator({
    PaypalPayment: { screen: PaypalPayment },
    Home: { screen: Home}
});

AppRegistry.registerComponent('paypal', () => NavigationScreen);
导出默认类主扩展组件{
建造师(道具){
超级(道具);
this.email=null;
this.amount=null;
this.device=null;
}
render(){
返回(
登录
this.email}/>
此.amount}/>
this.device}/>
this.props.navigation.navigate('paypappayment',{email:this.email})
}
title='Next'
/>
);
}
}
const NavigationScreen=StackNavigator({
PaypalPayment:{屏幕:PaypalPayment},
主页:{屏幕:主页}
});
AppRegistry.registerComponent('paypal',()=>NavigationScreen);

我发现了我的错误:

在我的App.js上,我没有调用我的
StackNavigator

export const RootNavigation = StackNavigator({
    Home: { screen: Home },
    PaypalPayment: { screen: PaypalPayment }
});

AppRegistry.registerComponent('paypal', () => RootNavigation);

export default class App extends Component<{}> {

   render() {
        return (
            <RootNavigation/>
        )
    }
}
export const RootNavigation=StackNavigator({
主页:{screen:Home},
PaypalPayment:{屏幕:PaypalPayment}
});
AppRegistry.registerComponent('paypal',()=>RootNavigation);
导出默认类应用程序扩展组件{
render(){
返回(
)
}
}
现在它开始工作了

我使用了以下文档:

我就是这样解决的

转到使用导航的组件的父组件。 并按如下方式调用该组件

<Component {...this.props} />


这使得子组件也可以使用
导航。

检查package.json并给我react导航的版本,之后我会帮助你。“react导航”:“^1.0.0-beta.13”你确定你没有在其他地方渲染
Paympayment
Home
?是的,我确定,PaypalPayment呈现一个网络视图,当我的应用程序启动时,我出现在主屏幕上,我刚刚解决了一个问题,昨天有人使用了相同的版本。。他犯的错误不在这里。那么,我可能需要看看你的项目。顺便说一句,为什么不使用Expo stack(带有create-react-native-app命令的scaffold)?