2017-01-13 27 views
0

我得到一个错误,当我尝试导入我的组件。 这是错误文本: “元素类型无效期望字符串(对于内置组件)或类/函数”。有错误,当我尝试导入我的组件在反应原生

主文件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> 
    } 
} 

如何解决我的进口?对不起,我的英语:D

回答

0

你如何导出你的Text2组件?

如果导出它作为默认的出口,就像这样:

export default Text2 

,那么你必须导入它是这样的:

import Text2 from './components/Text2' 
+0

我不写出口,ty –

0

导出您的组件将可以解决问题, 期待出口默认你只能用出口

export Text2 

然后你应该导入它l ike this:

import { Text2 } from './components/Text2'; 
相关问题