React Native + NativeBase +Exponent, Element type is invalid 报错

React Native + NativeBase +Exponent, Element type is invalid error

我对 React native、nativebase 和 Exponent 还很陌生。不幸的是,我什至无法显示简单的组件。我已经花了大约 6 个多小时来对 nativebase 文档中的简单教程组件进行故障排除。我觉得我只是缺少一些基本的东西,我真的很感激你的帮助。

这是我正在做的事情: 使用 Exponent XDE 运行 我的项目。 根据文档安装nativebase,此时没有报错

main.js

'use strict';
import React, { Component } from 'react';
import {
  AppRegistry,
} from 'react-native';
import { Container } from 'native-base';
import { CardImageExample } from './component/card.js';



AppRegistry.registerComponent('main', () => CardImageExample);

card.js

import React, { Component, Image } from 'react';
import { Container, Content, Card, CardItem, Thumbnail, Text, Icon } from 'native-base';

class CardImageExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Card>
                        <CardItem>
                            <Thumbnail source={require('./img/penguin-icon.png')} />
                            <Text>Instrumental Songs</Text>
                            <Text note>Guitar</Text>
                        </CardItem>

                        <CardItem>                        
                            <Image style={{ resizeMode: 'cover' }} source={require('./img/penguin.jpg')} /> 
                        </CardItem>

                        <CardItem>
                            <Icon name='ios-musical-notes' style={{color : '#ED4A6A'}} />
                            <Text>Listen now</Text>                        
                        </CardItem>
                   </Card>
                </Content>
            </Container>
        );
    }
}
export default CardImageExample;

当前错误: 元素类型无效:需要一个字符串(对于内置组件)或一个 class/function(对于复合组件)但得到:undefined

我完全不知道从哪里开始。谢谢

您必须像这样注册您的应用 Exponent.registerRootComponent(App)。 如果您使用指数。 示例:https://github.com/exponent/nativebase-example

你的 main.js 应该喜欢一些东西

import * as Exponent from 'exponent';
import React from 'react';
import First from './src/app';
import { Container, Header, Title, Content, Button, Left, Right, Body,Icon, Separator } from 'native-base';

class App extends React.Component {
 render() {
    return <First / > ;
 }
}
Exponent.registerRootComponent(App);