簡體   English   中英

在另一個類和導航中使用方法

[英]Use a method in another class and navigation

我正在編寫登錄用戶所需的應用程序,但是遇到問題。 我的App組件中有一個我想從其他組件中調用的getUser()方法。 我也有一個Login()方法,它使您可以導航到另一個頁面。 唯一的問題是我不能同時導出StackNavigator和App。 有沒有辦法導出StackNavigator和我的函數? 還是可以解決我的問題的其他解決方案?

class App extends Component<{}> {

    //get the user and return it
    _getUser() {
        return user
    }

    //authentify the user and go to is profil
    _userLogin() {
        navigate('Profil');
    }

    render() {
        const { navigate } = this.props.navigation;
        return (
            <View>
            <Button
            title="Login"
            onPress={() => this.Login() }
            />
            </View>
        );
    };
}

export default StackNavigator({
  Home: { screen: App },
  Profil: { screen: secondScreen },
});

謝謝你的幫助。

最終,我找到了一個解決方案,將用戶存儲在異步存儲中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM