I want to use .map like this. I define array like new array(4) and I dont give anyitem. So when I use like this :
imgUrls.map((url, index) => {
..
});
*this doesn't run 4 times. why ? I have default img so if imgUrls' first item is empty then use defaultimage. if second is empty then use defaultimage ... it should go like this but i couldnt solve *
My code which I try is below
constructor(props) {
super(props);
this.state = {
imgUrls: new Array(4),
defaultImage: require('../Images/addcircle.png'),
};
}
renderContent = () => {
const { imgUrls } = this.state;
return imgUrls.map((url, index) => {
try {
return (
<View key={index} >
<TouchableOpacity onPress={() => this.removeImg(index)}>
<View style={{ height: '100%', justifyContent: 'center', alignItems: 'center', aspectRatio: 1 }}>
<Image
source={{ uri: url } || this.state.defaultImage}
style={{ height: '90%', width: '90%' }}
/>
</View>
</TouchableOpacity>
</View>
);
} catch (error) {
console.log('error:', error);
}
});
};
render() {
console.log('in bar');
return (
<View style={styles.container}>
{this.renderContent()}
</View>
)
}