I am new in react-native and I m trying to get Image url from JSON API.When i run my code i got an error "source is undefined".So i just want to know that how can i get my Image url from JSON API.I am able to fetch the response of URL please check my code .
async componentDidMount() {
const DEMO_TOKEN = await AsyncStorage.getItem('isLoggedIn');
const url11 = 'http://104.197.28.169:3000/userProfile';
fetch(url11,{
method: 'GET',
headers: {
Authorization: 'Bearer ' + DEMO_TOKEN,
},
//Request Type
})
.then(response => response.json())
.then(responseJson => {
console.log('UserProresponse', responseJson)
this.setState({
dataSource : responseJson,
isLoading: false,
});
})
.catch(error => console.log(error));
}
<View style={styles.imageView}>
<Image style={styles.logoImg}
source={require(this.state.dataSource.data.photograph)}>
</Image>
</ VIew>
I am getting this console.log response.Here I am able to get the "firstName" , but I am unable to get the "photograph" from this response.Please check.
{
"message": "user profile",
"data": {
"id": 1,
"firstName": "Mohd",
"lastName": "Akram",
"dateOfBirth": "1995-08-25",
"gender": "male",
"maritalStatus": "unmarried",
"photograph": "images/2020-04-28T10-37-21.149Zdutch.png",
"userId": 2,
},
"status": 1
}