简体   繁体   English

React-Native:将组件导入App.js时出错

[英]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. 使用expo从组件导入默认类时出现错误,我搜索此错误,但未解决问题,组件返回object。

type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object type is invalid -- expected a string (for built-in components) or a class/function (for composite components) 但得到了:对象

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 App.js

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

app/components/login/index.js 应用/组件/登录/ 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>
        )
    }
}

In App.js use default import for Login component. App.jsLogin组件使用默认导入。 Also, export a root component from App.js 另外,从App.js导出根组件

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM