sorry for the silly question. I am relatively new to react native. I have got fetch working so I can get the json response back from the server. The server API returns a string if there is an error or returns an json object if its successful. is there any way to compare the response to see if its a string or json variable?
Not sure how to achieve the above any help would be appreciated.
here is my code
API.js
var API = {
SetupBuyOnline(email, serialNumber, platformType) {
var url = 'https://<urlomitted>/SetupBuyOnline';
return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
'operating_system': platformType,
'email': email,
'serialNumber': serialNumber
}
}).then((res) => res.json());
}
};
find userScreen.js
findUserScreen(){
// this.props.navigation.navigate('JoinNowScreen')
StudentApi.SetupBuyOnline('[email protected]', deviceId, "iOS")
.then((responseData) => {
if(typeof(responseData) == 'string')
{
console.log('got api call ' + responseData);
alert('test = ' + responseData);
}
else
{
console.log('got api call ' + responseData);
alert(responseData);
}
})
}
Not sure what I am doing wrong. Thanks in advance