I have the image source from props, when I concatenate source string like: require(../assets/images/${props.image})
. Then I call it on the source property of the image I got an error: Failed prop type: Invalid prop source
supplied to Image
.
Is there anyone can help, thanks so much <3
function Category(props) {
let image = `require(../assets/images/${props.image})`;
console.log(image);
return (
<TouchableOpacity style={styles.container}>
<View>
<Image style={{ width: 60, height: 60 }} source={image}></Image>
<Image style={{ height: 10, width: 12 }} source={require('../assets/images/Layer1.png')}></Image>
</View>
<View></View>
</TouchableOpacity>
);
}
Category is called by renderItem on FlatList, and item.image is the file name of image: layer1.png, layer2.png... Parent component - MainScreen:
function MainScreen({ navigation }) {
return (
<Screen style={styles.container}>
<Header isHome={true}>HOME</Header>
<ScrollView>
<View style={styles.main}>
<Carousel data={bannerSlide} />
<Text>Go to Detail</Text>
<View style={styles.category}>
<FlatList
style={styles.dishList}
data={dishList}
keyExtractor={item => item.label.toString()}
horizontal
snapToAlignment="center"
scrollEventThrottle={16}
showsHorizontalScrollIndicator={false}
renderItem={({ item }) =>
<Category
name={item.name}
image={item.image}
/>
}
/>
</View>
</View>
</ScrollView>
</Screen>
);
}