I am new to react native. I Have created a screen where I am using if else in function like this.
constructor(props) {
super(props);
this.state={
phpid = ''
}
}
validateInputs = (event) => {
const data = this.props.route.params.data
const { phpid } = this.state;
if (data.retail_information_data[0] != '') {
phpid == data.retail_information_data[0].id
}else{
phpid == null
}
AsyncStorage.multiGet(["application_id", "created_by"]).then(response => {
console.log(phpid)
fetch('https://njdnfech/Android_API_CI/uploaddata/tffmerchant_retail_details?query=', {
body: JSON.stringify([{phpid : phpid}])
})
.then((returnValue) => returnValue.json())
.then(function(response) {
console.log(response)
return response.json();
}
but I am getting = data.retail_information_data[0] = null or lets say empty then according to if else my else condition that is 'phpid == null' shuld run but even 'data.retail_information_data[0] = null' my else condition not running my console kepp saying 'TypeError: undefined is not an object (evaluating 'data.retail_information_data[0].id')' is any problem in my if else or how to write proper if else
Aucun commentaire:
Enregistrer un commentaire