nrs jayaram
nrs jayaram

Reputation: 3438

React-Native : error while import component to App.js

Getting error while import the default class from the components using expo, I search for this error but did not resolve the solution, the component returns object.

type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object

Error :

12:19:03: Warning: React.createElement: 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, or you might have mixed up default and named imports.

Check your code at registerRootComponent.js:35.
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

App.js

import Login from './app/components/login';

app/components/login/index.js

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

export default class Login extends Component {
    constructor(props){
        super(props);
        this.state = {}
    }
    render(){
        return(
            <View>
             <Text>Login</Text>
            </View>
        )
    }
}

Upvotes: 0

Views: 1929

Answers (1)

Vipin Kumar
Vipin Kumar

Reputation: 6546

In App.js use default import for Login component. Also, export a root component from App.js

import React from "react";
import Login from './app/components/login';

export default class App extends React.Component {
  render() {
    return <Login/>;
  }
}

Upvotes: 1

Related Questions