简体   繁体   English

在 if 语句中响应本机导航

[英]React Native Navigation in a if statement

Im making PIN code lock screen from react Native.我正在使用 React Native 制作 PIN 码锁屏。 When the user entered correct pin it gives a alert "Login success" When the user entered Wrong pin it gives a alert "Login failed" if user entered PIN 3 times, I want to show a new screen.当用户输入正确的 PIN 时,它会发出“登录成功”警报 当用户输入错误的 PIN 时,如果用户输入 PIN 3 次,它会发出“登录失败”警报,我想显示一个新屏幕。 so I write following code.所以我写了下面的代码。

const checkPinCode = (a,b) => {
        if(arrayEquals(a,b)){
            alert("Login success")
          }else {
            alert(" Login Failed  ");
            seterrorCounter(errorCounter+1)
          }      
              if (errorCounter>=2){
                 //Navigation code 
                 () => navigation.navigate('Wait')
              }
}

But this does not do the job.但这不起作用。 How can I navigate screens in a if else statement.如何在 if else 语句中导航屏幕。 You can find the complete code and emulator here - https://snack.expo.dev/@codewithbanchi/pincode你可以在这里找到完整的代码和模拟器 - https://snack.expo.dev/@codewithbanchi/pincode

Change your code to:将您的代码更改为:

const checkPinCode = (a,b) => {
        if(arrayEquals(a,b)){
            alert("Login success")
          }else {
            alert(" Login Failed  ");
            seterrorCounter(errorCounter+1)
          }      
              if (errorCounter>=2){
                 //Navigation code 
                 navigation.navigate('Wait') // remove () =>
              }
}

() => navigation.navigate('Wait') defines an unnamed function which es never called. () => navigation.navigate('Wait')定义了一个从未调用过的未命名的 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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