I am new to React Native! And having problems with properly loading the image off the JSON that I get from JsonPlaceHolder API. I set the state of the photos and the titles. The titles were able to load, however, photos were not be able to load properly. I did search and there are suggestions to replace http to https call would fix it. But No luck here. Please help! And Thank in Advance!
import React, { Component } from 'react';
import {
Image,
StyleSheet,
Text,
View,
} from 'react-native';
export default class App extends Component {
constructor(props){
super(props);
this.state = {
photos: '',
titles: ''
};
}
componentWillMount(){
this.fetchData();
}
fetchData = async () => {
let response = await fetch('http://jsonplaceholder.typicode.com/photos/1');
let json = await response.json();
this.setState({titles: json.title, photos: json.url.replace('http','https')});
};
render() {
console.log(this.state.photos)
return (
<View style={styles.container}>
<Image
source={{uri: this.state.photos}}
style={{height: 600, width: 600}}
resizeMode= 'cover'
/>
<Text>
Title: {this.state.titles}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
}
});