React-Native Invariant Violation:元素类型无效 [英] React-Native Invariant Violation: Element type is invalid
问题描述
当我要在我的iPhone Expo上运行我的本机应用程序时,此错误显示在红色背景区域。
When I going to run my react native app on my iPhone Expo this error displayed in red background area.
不变违规:元素type无效:期望一个字符串(对于内置组件)
或类/函数(对于复合组件)但得到:object。您
可能忘记从其定义的文件中导出您的组件。
Invariant Violation: Element 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.
这是'内部的App.js' src / components /'folder
this is the App.js inside the 'src/components/' folder
import React, { Component } from 'react';
import { View, Text } from 'react-native';
export default class App extends Component {
render() {
return (
<View>
<Text>Hello</Text>
</View>
);
}
}
这是react-native中的主要App.js app文件夹。
This is the main App.js in react-native app folder.
import App from './src/components/App';
我使用expo app运行此代码。如何解决此错误?
I used expo app for run this code. How can I solve this error?
推荐答案
Expo希望您从 /App.js导出组件
。但是现在你只导入 /App.js
。世博会没有收到任何组成部分。您需要导出导入的组件,如下所示:
Expo expects you to export a component from /App.js
. But right now you are only importing into /App.js
. Expo is not receiving any component to render. You need to export the component you imported like this:
export default App;
旁注:仅在必要时使用类组件。
On side note: Use a class component only if you must.
这篇关于React-Native Invariant Violation:元素类型无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!