从组件导入默认类时出错 使用 expo ,我搜索了此错误,但没有解决问题,组件返回了对象。
type is invalid -- expected a string (for built-in components) or a class/function (for composite components)
但得到:对象
错误:
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>
)
}
}
答案 0 :(得分:0)
在App.js
中为Login
组件使用默认导入。另外,从App.js
import React from "react";
import Login from './app/components/login';
export default class App extends React.Component {
render() {
return <Login/>;
}
}