Willnewbie
Willnewbie

Reputation: 1

Uncaught Error: Invariant Violation: Element type is invalid: expected a string for built-in components or a class/function but got: object

js and can't figure out this problem:Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

My code in App.js

import React from "react";
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import WelcomeScreen from "./screens/WelcomeScreen";
import HomeScreen from "./screens/HomeScreen";
const Stack = createStackNavigator ()

const App = () => {
    return (
            <NavigationContainer>
                <Stack.Navigator screenOptions={{headerShown: false}}>
                    <Stack.Screen name="WelcomeScreen" component={WelcomeScreen}/>
                    <Stack.Screen name="HomeScreen" component={HomeScreen}/>
                </Stack.Navigator>
            </NavigationContainer>
        );
};

export default App

The first screen: WelcomeScreen works fine, but my HomeScreen doesn't work.
code in HomeScreen:

````import React from "react";
import Text from "react"
import View from "react"

const HomeScreen = () => {
    return (
        <View>
            <Text>Det er min home</Text>
        </View>
        )
    };

export default HomeScreen

I hope you can help me

Upvotes: 0

Views: 79

Answers (1)

user15137953
user15137953

Reputation: 47

Your imports on HomeScreen are wrong. Firstly you are using React Native so you need to import from "react-native" not from "react".

"View" and "Text" etc. needs to be in an clamp: import { View, Text} from "react-native"

Btw. if you use VSCode, theres an extension called ES7+ for shortcuts just type "rnfe" or "rnfes" in a new file and hit enter.

I hope this helps!

Upvotes: 1

Related Questions