相关疑难解决方法(0)

React-Navigation 将函数传递给 screenProps

我正在使用 React Native、Expo 和 React Navigation 创建一个应用程序,但我不知道传递 props 和函数的正确方法。

我已经复制了我将在其上构建的导航器的 Expo 方法,但现在我只有 App.js 调用以下 AppNavigator -> MainSwitchNavigator -> HomeScreen

然后,我使用带有身份验证器的 Amazon AWS Amplify HOC 包装了 Expo 期望的主要导出应用程序。现在我可以使用亚马逊的 Cognito 服务登录到我的应用程序并安全地显示 hello world。

如果我想注销,我可以使用我目前在 App 的道具上使用的注销功能。

class App extends React.Component {

  constructor(props) {
    super(props);
    this.signOut = this.signOut.bind(this);
  }

  signOut() {
    Auth.signOut().then(() => {
      this.props.onStateChange('signedOut', null);
      console.log("signed out");
    }).catch(e => {
      console.log(e);
    });
  }

  render () {
    return (
        <View style={styles.container}>
          <AppNavigator screenProps={{
            signOut: () => {this.signOut}
            }}/>
        </View>
    );
  }
}

export …
Run Code Online (Sandbox Code Playgroud)

amazon-cognito react-native react-navigation expo

0
推荐指数
1
解决办法
8625
查看次数