【问题标题】:React-Navigation: Invariant Violation: Element type is invalid: expected a string but got undefinedReact-Navigation:不变违规:元素类型无效:预期为字符串但未定义
【发布时间】:2019-05-09 21:55:46
【问题描述】:

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

接下来,我将向您展示我的代码、我拥有的版本以及我对 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

  "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 行是带有 Provider 组件的行。 看:不添加 StackNavigator 我没有错误。

import AppNavigator from "./routers/Router"

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



export default App;

【问题讨论】:

  • LoginFormSetting默认导出还是命名导出?
  • 显示你的 App.js 文件
  • app.js 的第 21 行有问题。你可以在这里发布 app.js 文件吗?
  • @rickdenhaan 他们是默认导出
  • 我将 App.js 添加到问题中。

标签: reactjs react-native react-navigation


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2019-12-31
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 2019-10-24
    • 2019-06-07
    • 2020-02-29
    • 2017-12-24
    • 2017-07-25
    相关资源
    最近更新 更多