React-Navigation: Invariant Violation: 元素类型无效:需要一个字符串但未定义 [英] React-Navigation: Invariant Violation: Element type is invalid: expected a string but got undefined

查看:45
本文介绍了React-Navigation: Invariant Violation: 元素类型无效:需要一个字符串但未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 React-Navigation 的 StackNavigator 时遇到错误.

I'm getting an error while using StackNavigator of React-Navigation.

接下来我将向您展示我的代码、我拥有的版本以及我对 package.json 的所有配置

Following I'm showing you my code, the version that I have, and all my configuration of package.json

代码如下:

import {React} from 'react'
import { StackNavigator } from 'react-navigation';
import LoginForm from '../view/screen/LoginForm'
import Setting from '../view/screen/Setting'

export const AppNavigator = StackNavigator({
  Login: { screen: LoginForm },
  Setting: { screen: Setting }
});

这是我的配置:

 1. react-navigation@1.5.13 
 2. npm version: 5.6.0
 3. react-native-cli: 2.0.1
 4. react-native: 0.57.5

这是我的 package.json

This is my package.json

  "dependencies": {
    "firebase": "^5.5.9",
    "react": "16.6.1",
    "react-native": "0.57.5",
    "react-native-elements": "^0.19.1",
    "react-native-navigation": "^2.2.0",
    "react-native-ui-lib": "^3.6.1",
    "react-navigation": "^1.0.0-beta.22",
    "react-redux": "^5.1.1",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  }

错误显示在屏幕截图中

App.js 是.21 行是提供程序组件的那一行.看:没有添加 StackNavigator 我没有错误.

The App.js is. The 21 line is the one with the Provider Component. Look: without adding the StackNavigator I have no error.

import AppNavigator from "./routers/Router"

    render(){
        return (
            <Provider store={createStore(reducers, {}, applyMiddleware(ReduxThunk))}>
                <AppNavigator />
            </Provider>
        )
    }
}



export default App;

推荐答案

解决方案是将 AppsNavigator 中的 export const 更改为 export default.

The solution is to change export const in AppsNavigator with export default.

export default AppNavigator = StackNavigator({
  Login: { screen: LoginForm },
  Setting: { screen: Setting }
});

这篇关于React-Navigation: Invariant Violation: 元素类型无效:需要一个字符串但未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆