根据函数返回的内容设置导航值

问题描述 投票:0回答:0

当我调用登录函数时,这是我得到的错误:

Error: You need to specify name or key when calling navigate with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigate for usage. 

这是我的代码:

login.jsx

<TouchableOpacity
                style={styles.button}
                onPress={() => navigation.navigate(this.onClick())}>
                <Icon
                  style={styles.buttonIcon}
                  name="arrow-right"
                  size={30}
                  color="white"
                  type="feather"
                />

这是函数:

ParticleAuth.js

onClick = async () => {
  this.init();
  this.setLanguage();
  this.setChainInfo();
  this.login();
  const result = await particleAuth.isLogin();
  console.log('Result:', result);
  if (result) {
    return "LoggedIn"; // LoggedIn & Error are names of screens
  } else {
    return "Error";
  }
};

根据报错,我要给navigation.navigate预置值。我的替代代码可能是什么?

谢谢!

javascript react-native react-navigation
© www.soinside.com 2019 - 2024. All rights reserved.