首页 文章

当我尝试在本机中导入我的组件时出错

提问于
浏览
-1

我尝试导入我的组件时遇到错误 . 这里是错误文本:“元素类型无效,期望字符串(对于内置组件)或类/函数” .

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

2 回答

  • 0

    如何导出Text2组件?

    如果您将其导出为默认导出,如下所示:

    export default Text2
    

    那么你必须像这样导入它:

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

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

    export Text2
    

    然后你应该像这样导入它:

    import { Text2 } from './components/Text2';
    

相关问题