React Native error: Element type is invalid: expected a string or a class/function but got: object React Native error: Element type is invalid: expected a string or a class/function but got: object android android

React Native error: Element type is invalid: expected a string or a class/function but got: object


This is probably caused by some JS module export/import issues in your program, typically for one of the two reasons listed below:

  • You forget to export, or you export something incorrectly
  • You import something that doesn't exist, or you import something incorrectly

I ran into similar error, but in my case, it is not caused by export but caused by import, and I used the import statement incorrectly to import something that doesn't exist in the module.

In my case, the import was incorrectly written as:

import { MyComponent } from './MyComponents/MyComponent'

while actually it should be:

import MyComponent from './MyComponents/MyComponent'

And it drove me crazy and took me a whole day to figure it out and I hope this will save several hours for some people.


Change your SwitchView definition to

export default class SwitchView extends Component...


Modify your SwitchView to this:

import Feed from './app/pages/Feed/Feed';import Board from './app/pages/Board';import Wiki from './app/pages/Wiki';export default class SwitchView extends Component {render(){    var { id } = this.props;    switch (id) {        case "FeedView":            return <Feed/>        case "WikiView":            return <Wiki/>        case "BoardView":            return <Board/>    }}}