[英]React Native : Async and Await is a reserved word error inside onPress
我面臨一個奇怪的問題。 在我的本機反應應用程序中,我有一個觸發onPress
的Googlebutton
,它會檢查其中的條件,但問題是我有await
reserved word,它返回一個錯誤說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);
}
}
}
/>
這是我嘗試過的我在等待之前放置了異步(hasUserSetPinCode)但是它在我的控制台中沒有返回任何值,它似乎不起作用
放一個異步
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
放在使用它的 function 之前。
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);
}
}
}
/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.