undefined不是对象(评估'component.router.getStateForAction')

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

当我在我的模拟器上加载我的react本机应用程序时,我看到以下错误。它似乎与我对react-navigation的使用有关。但在谷歌上搜索错误,我无法找到我所缺少的东西。

error

它在此代码段中调出“wrappedComponent”。

function WithAuth(WrappedComponent) {
  return class extends React.Component {
    constructor(props) {
      super(props);

      this.state = {
        ready: false,
        session: null,
      };

      this.handleOnSignIn = this.handleOnSignIn.bind(this);
      this.handleOnSignUp = this.handleOnSignUp.bind(this);
      this.handleOnSignOut = this.handleOnSignOut.bind(this);
    }

    async componentDidMount() {
      await LocalStorage.init();
      let session;
      try {
        session = await Auth.currentSession();
      } catch (err) {
        console.log(err);
        session = null;
      }
      this.setState({
        session,
        ready: true,
      });
    }

    handleOnSignIn(session) {
      this.setState({ session });
    }

    handleOnSignUp() { }

    handleOnSignOut() {
      Auth.signOut();
      this.setState({ session: null });
    }

    render() {
      const { ready, session } = this.state;
      console.log('Rendering HOC', ready, !!session);
      const {
        onSignIn,
        onSignUp,
        doSignOut,
        ...otherProps
      } = this.props;

      return (
        ready && (
          <WrappedComponent
            session={session}
            onSignIn={onSignIn || this.handleOnSignIn}
            onSignUp={onSignUp || this.handleOnSignUp}
            doSignOut={doSignOut || this.handleOnSignOut}
            auth={Auth}
            {...otherProps}
          />
        )
      );
    }
  }
}

export default WithAuth;

这是利用以下app.js代码:

Amplify.configure(awsmobile);

const App = createDrawerNavigator({
  FirstScreen: {
    screen: props => <First rootNavigator={props.navigation} screenProps={{ ...props.screenProps }} />,
    navigationOptions: {
      drawerLabel: ' ',
    },
  },
}, { initialRouteName: 'FirstScreen' });


const AppContainer = createAppContainer(props => <App screenProps={{ ...props }} />);

export default WithAuth(AppContainer);

(导出是调用WithAuth的。)

这部分代码是使用react-navigation 2.0从应用程序中提取的,我已经更新到3.0并且我在想我现在需要的东西,但是,我找不到它。

任何帮助表示赞赏!

react-native react-navigation
1个回答
0
投票

AppContainer设置为您的根组件,如下所示:

const AppContainer = createAppContainer(props => WithAuth(_ => <App screenProps={{ ...props }} />));

export default AppContainer;
© www.soinside.com 2019 - 2024. All rights reserved.