2017-10-14 106 views
1

我是新的反應原生,我試圖使用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); 
+0

檢查的package.json和給我反應過來,導航版,在那之後我會幫你的。 –

+0

「react-navigation」:「^ 1.0.0-beta.13」 –

+0

您確定您沒有在其他地方呈現「PaypalPayment」或「Home」嗎? –

回答

0

我發現了什麼是我的錯誤:

在我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

相關問題