当我使用renderItme时,react-native-snap-carousel返回“无法读取未定义的属性'concat'”

时间:2019-06-20 06:03:14

标签: javascript reactjs react-native react-native-android react-native-snap-carousel

我正在学习React-Native,并在我的项目中使用react-native-snap-carousel。 我想显示一些图像,但出现错误Cannot read property 'concat' of undefined

这是我的代码。

const HomePage = (props) => {
   let imageList = ['../images/index-bg.png', '../images/down.png'];

   const renderImage = ({ item, index }) => {
       return (
            <View>
                <Image source={require(item)}></Image>
            </View>
        )
    };

   return (
     <View> 
            <Carousel
                loop={true}
                autoplay={true}
                data={imageList}
                renderItem={renderImage}
                sliderWidth={pxToDp(50)}
                itemWidth={pxToDp(100)}
            />

     </View>
   )

}

如果我更改

          <View>
                <Image source={require(item)}></Image>
            </View>

          <View>
                <Image source={'../images/index-bg.png'}></Image>
            </View>
···
it works well


I expect it would work like [Usage](https://github.com/archriss/react-native-snap-carousel) but it doesn't work.

1 个答案:

答案 0 :(得分:0)

您尝试过吗?

let imageList = [require('../images/index-bg.png'), require('../images/down.png')];

然后

  <View>
    <Image source={item}></Image>
  </View>

必须在运行时之前定义RN中图像的必需来源

让我知道它是否有效!