2

我正在显示反应原生闪屏并尝试将其隐藏在 useEffect 中,但如果我在 App.js 中使用 AWS Authenticator,则不会调用 useEffect。当我不使用身份验证器时,它工作正常。

应用程序.js

import Amplify from 'aws-amplify';
import config from './src/aws-exports';
import { withAuthenticator } from 'aws-amplify-react-native';
import Auth from '@aws-amplify/auth';
import SplashScreen from 'react-native-splash-screen';
import { useEffect } from 'react';

function App (){
  useEffect(() => {
    SplashScreen.hide();
  });

  return ( 
    <View>
    </View>
  );
};
export default withAuthenticator(App); 

如果我删除最后一行,它可以在没有 Authenticator 的情况下正常工作。

4

1 回答 1

1

您需要更改状态才能触发 useEffect。withAuthenticator 负责整个登录过程。因此,要包括自定义,我建议使用Authenticator(这是 WithAuthenticator 中的包装组件)。它具有onStateChange属性,可用于检测权限更改。

例子:

<Authenticator 
   // Fired when Authentication State changes, use it to hide/show stuff
   onStateChange={(authState) => console.log(authState)} 
>
   // Default components can be customized/passed in as child components. 
   // Define them here if you used hideDefault={true}
</Authenticator>

来源:AWS amplify Authenticator

于 2021-10-07T07:37:57.603 回答