简体   繁体   中英

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

I'm facing a weird problem. In my react native app I have a Googlebutton which trigger onPress and it will check the condition within it, but the problem is I have await reserved word which returns me an error says Unexpected reserved word await I'm trying to apply Pincode

Main Code

 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);
    }
   }
 }
/>

This is what I've tried I've put async (hasUserSetPinCode) before the await but it returns no value in my console, it seems it's not working

putting an 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() => {
     /* ------------------ 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);
        }
     }
  
/>

在此处输入图像描述

Place async before the function in which it is used.

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);
    }
   }
 }
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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