【问题标题】:Show loading spinner in react native app while waiting for firebase authentification在等待 Firebase 身份验证时在反应本机应用程序中显示加载微调器
【发布时间】:2021-04-02 19:30:42
【问题描述】:

我想在我的 react 本机应用程序中实现一个加载微调器,同时等待完成 firebase 身份验证。

这是我的登录功能:

async (email, password) => {
    try {
      await auth().signInWithEmailAndPassword(email, password);
    } catch (e) {
      alert(e);
    }
}

提前感谢您的回答!

【问题讨论】:

    标签: firebase react-native firebase-authentication asyncstorage


    【解决方案1】:

    如果您使用功能组件,您可以使用 react 中的 useState Hook 定义加载状态

    const [loading, isLoading] = useState(false);
    

    在您的代码中,它将如下所示:

    login: async (email, password) => {
          try {
            setLoading(true);
            await auth().signInWithEmailAndPassword(email, password);
            setLoading(false);
          } catch (e) {
            alert(e);
          }
        }
    

    基于该状态,您可以渲染:

    if(isLoading) {
      return (
           <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
               <ActivityIndicator/>
           </View>
      )
     }
    

    【讨论】:

    • 非常感谢,您的回答对我帮助很大
    • @LyazidKabbaj 我很高兴听到这个消息!如果您的问题已得到解答,请不要忘记将其标记为答案 :)
    猜你喜欢
    • 2020-12-22
    • 1970-01-01
    • 2020-04-01
    • 2022-11-24
    • 1970-01-01
    • 2017-12-25
    • 2023-03-13
    • 2022-12-08
    • 2020-05-18
    相关资源
    最近更新 更多