反应原生:undefined不是一个对象(评估'_this2.props.navigation.navigate')
问题描述:
我是新的反应原生,我试图使用StackNavigator,但它不工作 我想打电话给一个组件并在你点击一个按钮时呈现它。 但我发现了这个错误: undefined is not an object (evaluating '_this2.props.navigation.navigate')
反应原生:undefined不是一个对象(评估'_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);
答
我发现了什么是我的错误:
在我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/>
)
}
}
现在它的工作。
我用这个文档:https://reactnavigation.org/docs/intro/#Introducing-Stack-Navigator
检查的package.json和给我反应过来,导航版,在那之后我会帮你的。 –
“react-navigation”:“^ 1.0.0-beta.13” –
您确定您没有在其他地方呈现“PaypalPayment”或“Home”吗? –