React Native:Async 和 Await 是 onPress 中的保留字错误

React Native : Async and Await is a reserved word error inside onPress

我遇到了一个奇怪的问题。在我的本机反应应用程序中,我有一个 Googlebutton 触发 onPress 并且它将检查其中的条件,但问题是我有 await 保留字 returns 我错误提示 Unexpected reserved word await 我正在尝试申请 Pincode

主要代码

 import PINCode, {hasUserSetPinCode,resetPinCodeInternalStates,deleteUserPinCode,
 } from "@haskkor/react-native-pincode";

<GoogleSigninButton
   style={{ width: 252, height: 58 }}
   size={GoogleSigninButton.Size.Wide}
   color={GoogleSigninButton.Color.Dark}
   onPress={() => {

   const hasPin = await hasUserSetPinCode();
   if (fingerprint === true) {
       googleLogin();
   }

   else if (hasPin) {
       console.log("Alert pinnn should pop up");
   }

   else {
      console.log("Alert should pop up");
      setModalVisible(true);
    }
   }
 }
/>

这是我试过的我已经在等待之前放置了 async (hasUserSetPinCode) 但它 returns 在我的控制台中没有价值,似乎不是工作

放置一个异步

import PINCode, {hasUserSetPinCode,resetPinCodeInternalStates,deleteUserPinCode,
}from "@haskkor/react-native-pincode";

<GoogleSigninButton
     style={{ width: 252, height: 58 }}
     size={GoogleSigninButton.Size.Wide}
     color={GoogleSigninButton.Color.Dark}
     onPress={async() => {
     /* ------------------ The async below Doesn't work ----------------------------------- */
     
     const hasPin = await hasUserSetPinCode();
        if (fingerprint === true) {
           googleLogin();
        }
        else if (hasPin) {
           console.log("Alert pinnn should pop up");
        }
        else {
           console.log("Alert should pop up");
           setModalVisible(true);
        }
     }
  
/>

async 放在使用它的函数之前。

import PINCode, {hasUserSetPinCode,resetPinCodeInternalStates,deleteUserPinCode,
 } from "@haskkor/react-native-pincode";

<GoogleSigninButton
   style={{ width: 252, height: 58 }}
   size={GoogleSigninButton.Size.Wide}
   color={GoogleSigninButton.Color.Dark}
   onPress={async () => {

   const hasPin = await hasUserSetPinCode();
   if (fingerprint === true) {
       googleLogin();
   }

   else if (hasPin) {
       console.log("Alert pinnn should pop up");
   }

   else {
      console.log("Alert should pop up");
      setModalVisible(true);
    }
   }
 }
/>