如何在NativeBase中使用DeckSwiper元素而不会出现“元素类型无效”错误?

时间:2016-12-25 20:03:55

标签: javascript android ios react-native native-base

我在视图中使用NativeBase的DeckSwiper(docscode)并且每次都会出错:

Warning: React.createElement: type should not be null, undefined, 
boolean, or number. It should be a string (for DOM elements) or a 
ReactClass (for composite components). Check the render method of `CardSwiper`.

此标记有效:

  <View flex>
    <DeckSwiper dataSource={cards} renderItem={(item) => {
        console.log(item);
        return (
            <Text flex>{item.text}</Text>
        )
    }}/>

但是Text(来自他们的网站)在此标记中的修改失败,出现上述错误:

<Card style={{
    elevation: 3
}}>
    <CardItem>
        <Thumbnail source={item.image}/>
        <Text>{item.text}</Text>
        <Text note>NativeBase</Text>
    </CardItem>
    <CardItem>
        <Image style={{
            resizeMode: 'cover',
            width: null
        }} source={item.image}/>
    </CardItem>
    <CardItem>
        <Icon name="ios-heart" style={{
            color: '#ED4A6A'
        }}/>
        <Text>{item.name}</Text>
    </CardItem>
</Card>

我无法弄清楚我是否使用它错误或文档已关闭或这是一个错误。这是什么问题?

1 个答案:

答案 0 :(得分:0)

您必须从“ react-native”导入“ Image”,而不是从“ native-base”导入

示例代码:

import { Image } from 'react-native';
import { Container, Header, View, DeckSwiper, Card, CardItem, Thumbnail, Text, Left, Body, Icon } from 'native-base';