Vladyslav Zavalykhatko
Vladyslav Zavalykhatko

Reputation: 17414

React Native, element type is invalid: expected a string (for built-in components)

The same issue was already solved in several posts, but non of them helped me (I'm new to React Native, so possibly there is a solution, but I can't find it)

My code uses route and screen. App.js:

import React from 'react';
import { StackNavigator } from 'react-navigation';

import HomeScreen from './screens/HomeScreen.js';

const App = StackNavigator({
  Home: { screen: HomeScreen }
});

HomeScreen.js:

import React, { Component } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';

export default class HomeScreen extends Component {
  onPressLearnMore() {

  }

  render() {
    return (
      <View style={styles.container}>
        <Button title="Learn More" onPress={() => this.onPressLearnMore()} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

What is wrong?

The project structure:

enter image description here

Upvotes: 0

Views: 152

Answers (2)

soutot
soutot

Reputation: 3671

You don't need to define the file type in your import.

Change this import HomeScreen from './screens/HomeScreen.js';

To this import HomeScreen from './screens/HomeScreen';

Hope it helps.

Edit: Just to gather all information in this answer, as suggested in the comments you should also export your App.js

Upvotes: 0

Talor A
Talor A

Reputation: 85

you must export default App in app.js

Upvotes: 2

Related Questions