React-Navigation: Invariant Violation: Element type is invalid: expected a string but got undefined

冷暖自知 提交于 2021-01-29 08:16:00

问题


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

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

Here is the code:

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 }
});

This is my configuration:

 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

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"
  }

The error is show in the screenshot

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;

回答1:


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

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


来源:https://stackoverflow.com/questions/53681282/react-navigation-invariant-violation-element-type-is-invalid-expected-a-strin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!