简体   繁体   English

我有一个 react native 组件,我正在尝试通过 connect 将该组件连接到 react-redux,但出现错误

[英]I have a react native component and i am trying to connect that component to react-redux through connect, but i am getting error

I have a react native component and i am trying to connect that component to react-redux through connect, but i am getting error stating the getScreen() defined for route didnt returned a valid screen.我有一个 react native 组件,我正在尝试通过 connect 将该组件连接到 react-redux,但是我收到错误消息,指出为路由定义的 getScreen() 没有返回有效的屏幕。 But when i remove connect from the component it works fine in the navigator.But when i use connect , i am getting the error.但是当我从组件中删除 connect 时,它在导航器中工作正常。但是当我使用 connect 时,我收到错误消息。

Below is the component下面是组件

class LoginScreen extends Component {

  componentDidMount() {
    // this.props.login();
    console.log(this.props.auth, 'this is staet')
  }

  render() {
    return (
      <Box f={1}>
        <Box f={1}>
          <ImageBackground source={images.bg} style={styles.container}>
            <Box bg="white" f={0.5} w="100%" p="lg" style={styles.abs}>
              <Text size={'2xl'}>
                OTP has been
              </Text>
              <Text size={'2xl'}>
                send to your mobile
              </Text>
              <Text size={'md'}>
                Verify your mobile number
              </Text>
            </Box>
          </ImageBackground>
        </Box>
      </Box>
    );
  }
}

export default
 connect(
  mapStateToProps, {
    login
  }
) 
(LoginScreen);

And here is the navigator file这是导航器文件

const AuthNavigator = createStackNavigator({
    Login: {
        getScreen: () => require('./LoginScreen').default
    }
}, {
    navigationOptions: {
        header: null
    }
})


const TabNavigator = createBottomTabNavigator({
    Home: {
        getScreen: () => require('./HomeScreen').default
    }
})


const MainNavigator = createStackNavigator({
    Tab: TabNavigator
});


const AppNavigator = createSwitchNavigator({
    Splash: {
        getScreen: () => require('./SplashScreen').default
    },
    Auth: AuthNavigator,
    Main: MainNavigator
}, {
    initialRouteName: 'Splash'
});

试试这个代码。

import LoginScreen from './screens/LoginScreen' const AuthNavigator = createStackNavigator({ Login: { screen: LoginScreen, } }, { navigationOptions: { header: null } })

暂无
暂无

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

相关问题 当我用 Provider 包装我的应用程序组件时,为什么会出现此错误? Redux 和 React Native - Why am I getting this error when I wrapped my App component with Provider? Redux and React Native 我在以下 react-redux 代码中收到初始化错误 - I am getting initialization error in the following react-redux code 当组件“连接”到react-redux存储时,我是否需要React.PureComponent? - Do I need React.PureComponent when the component is `connect`ed to react-redux store? 如何访问包装在 React-Redux 的连接 function 中的功能性子组件中的引用? - How do I access a ref in a functional child component that is wrapped in React-Redux's connect function? 我在使用Redux响应本机中获取数据时遇到错误 - I am getting an error while fetching data in react native with redux 为什么在此React组件代码中出现解析错误? - Why am I getting a parsing error in this React component code? 为什么我在 okta-react 安全组件上收到此错误? - Why am I getting this error on okta-react Security component? 我的地图函数返回 React 组件时出错 - I am getting an error in my map function returning React component 我正在尝试将此 React class 组件更改为功能组件 - I am trying to change this React class component into a Functional Component React-Redux:我是否必须对来自单个组件树的所有组件使用 connect() 和 map 状态/调度? 有没有办法只做一次? - React-Redux: Do I have to use connect() and map state/dispatch on all my components from a single component tree? Is there a way to do it only once?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM