Issue
When I going to run my react native app on my iPhone Expo this error displayed in red background area.
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in.
this is the App.js inside the 'src/components/' folder
import React, { Component } from 'react';
import { View, Text } from 'react-native';
export default class App extends Component {
render() {
return (
<View>
<Text>Hello</Text>
</View>
);
}
}
This is the main App.js in react-native app folder.
import App from './src/components/App';
I used expo app for run this code. How can I solve this error?
Solution
Expo expects you to export a component from /App.js
. But right now you are only importing into /App.js
. Expo is not receiving any component to render. You need to export the component you imported like this:
export default App;
On side note: Use a class component only if you must.
Answered By - THpubs
Answer Checked By - Cary Denson (JavaFixing Admin)