I'm using FlatList to render multiple Images on the Screen. I want to render placeholder Image when item.img is null (items are fetched from react-redux).
Problems:
I want to use placeholder image using 'require'. And it's using single curly brace.
<Image source={ require('../assets/images/robot-prod.png') } style={styles.palceholderImage}/>. While normal Image rendering use two curly braces{{uri: item.img}}.Should I inline
if(item.img)operator?
Here is _renderItem function.
_renderItem = ({item}) => {
let imgUrl = item.img;
return (
<TouchableWithoutFeedback
onPress={() => this._handleCategoryPress(item.id)}>
<Image
key={item.id}
source={{uri: item.img}}
style={styles.rowImage}
resizeMode="cover"
/>
</TouchableWithoutFeedback>
);
}
This is API response
[
{
"id": 1,
"name": "Gym",
"image": "www.aws.blahblahblah"
},
{
"id": 2,
"name": "School",
"image": null
},
{
"id": 3,
"name": "hollymo",
"image": "www.aws.blahblahblah"
},
Thanks