简体   繁体   English

在 React Native 中使用 AWS Amplify 登录后如何呈现自定义组件?

[英]How to render a custom component after sigin with AWS Amplify in React Native?

I want render my app after sigin in using Amplify react ui components.我想在使用 Amplify react ui 组件登录后呈现我的应用程序。 Here is what my code looks like.这是我的代码的样子。

    <View style={styles.container}>
        <Logo />
        <Authenticator usernameAttributes="email">
            <Home />
        </Authenticator>
    </View>

Here is the Home component.这是 Home 组件。

const Home = (props) => {
if (props.authState === 'signedIn') {
    return <Text>Home</Text>;
} else {
    return <></>;
}};

Here is how it looks after signin.这是登录后的样子。

You need to pass something to the Home component.您需要将某些内容传递给 Home 组件。

Something like this:像这样的东西:

<View style={styles.container}>
    <Logo />
    <Authenticator usernameAttributes="email">
        <Home authState={authState}/>
    </Authenticator>
</View>

Where authState receives a variable that specifies whether the user is signed in or not as a string for you to be able to compare it using props.authState === 'signedIn'其中 authState 接收一个变量,该变量指定用户是否已登录作为字符串,以便您能够使用 props.authState === 'signedIn' 进行比较

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM