I have this function which supposed to loop through 20 elements of (smn) Array to show the elements that meets the IF condition, with this code I got only the first array elements:
renderSMN() {
const smn = ['fb', 'twt', 'snp', 'ins', 'ytu', 'lnk', 'tik', 'beh', 'pin', 'tmp', 'www', 'eml', 'wap', 'msg', 'tlg', 'lin', 'wch', 'skp', 'snd', 'oth'];
for (let i = 0; i < 20; i++) {
//alert(this.state.data.smu_+smn[i]);
alert(i);
if (this.state.data.smu_+smn[i] != "") {
return (
<View style={{ margin: 5 }}>
<TouchableOpacity onPress={() => {
this.props.navigation.navigate('Result', { postId: item.uid, otherParam: 'Pass whatever you want here', });
}}>
<Image source={{ uri: 'http://localhost/rest/smn/' + smn[i] + '.png' }} style={{ width: 100, height: 100, right: 0, }} />
</TouchableOpacity>
<Text>{i}</Text>
</View>
);
}
This how I get the Data from JSON file:
fetch('http://localhost/rest/api/single_read.php/?id=' + postId, {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
data: responseJson
})
})
.catch((error) => {
console.error(error);
});