[英]have an error when i try import my component in react native
I got an error when i try import my component.当我尝试导入我的组件时出现错误。 here is text of error : "element type is invalid expected a string (for built-in components) or a class/function".
这是错误文本:“元素类型无效,预期为字符串(对于内置组件)或类/函数”。
Main file index.android.js主文件 index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import {Text2} from './components/Text2';
class p001_lesson extends Component {
render() {
return (
<View>
<Text2/>
</View>
);
}
}
AppRegistry.registerComponent('p001_lesson', () => p001_lesson);
second file Text2.js
<pre>
import React, {Component} from 'react';
import {
Text,
} from 'react-native';
class Text2 extends Component {
render() {
return <Text>some text here</Text>
}
}
How i can fix my import?我如何修复我的导入? Sorry for my English :D
对不起我的英语 :D
How do you export your Text2 component?你如何导出你的 Text2 组件?
If you exported it as a default export, like this:如果您将其导出为默认导出,如下所示:
export default Text2
then you have to import it like this:那么你必须像这样导入它:
import Text2 from './components/Text2'
exporting your components will can solve the problem, expect export default you can use only export导出您的组件将可以解决问题,期望导出默认值您只能使用导出
export Text2
Then you should import it like this:然后你应该像这样导入它:
import { Text2 } from './components/Text2';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.