我是react-native新手,我正在尝试使用StackNavigator,但它不起作用
我正在尝试调用一个组件并在您单击按钮时呈现它。
但我收到此错误:
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
关于react-native - native react :undefined is not an object (evaluating '_this2.props.navigation.navigate' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46743628/