I'm new to React-Native and trying to start with it by following a beginner's tutorial. I've followed the tutorial and created a "Header" component and try to export and import it and eventually use it. Unfortunately I get an error: Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object. I went across these two questions:
- Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object
- Uncaught Error: Invariant Violation: Element type is invalid: expected a string
But none of them helped me to solve my issue.
These are my files and their contents:
index.js
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('albums', () => App);
App.android.js
// Import section
import React from 'react';
import { AppRegistry } from 'react-native';
import Header from './src/components/header';
// create a component
const App = () => (
<Header />
);
// Render it to the device
AppRegistry.registerComponent('albums', () => App);
header.js
// Import labraries for making a component
import React from 'react';
import { Text } from 'react-native';
// Make a component
const Header = () => {
return <Text>Albums</Text>
};
// Make the component available to other parts of the app
export default Header;
I've also tried to import header like this (but it didn't help):
import { Header } from './src/components/header';
I would really appreciate any help to solve this issue. Thanks in advance :)
P.S I'm using React-Native version 0.49.1