[英]React-Native : error while import component to App.js
使用expo從組件導入默認類時出現錯誤,我搜索此錯誤,但未解決問題,組件返回object。
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';
應用/組件/登錄/ 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>
)
}
}
在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/>;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.