I am new to coding and I have a doubt with respect to if - else if statements for props
The following code snippet is working, but I want to add another property in props and if 'abc' is unavailable, only then props value 'pqr' should be added to path.
render() {
if (this.props.abc?.status !== 'available') return null;
console.info('Log value= ',this.props);
const path = this.props.abc.value;
return (
<View
getfile={path}
console.info('finished loading:', path);
}
/>
);
}
I want to write something like
render() {
if (this.props.abc?.status !== 'available') return null;
else if (this.props.pqr?.status !== 'available') return null;
console.info('Log value= ',this.props);
if (this.props.abc != null) {
const path = this.props.abc.value;
}
else if (this.props.pqr != null) {
const path = this.props.pqr.value;
}
/* I know the above if -else if statement will fail as props value for 'abc' might not be null yet not have the required value in which case it would never go to the else if statement. */
return (
<View
getfile={path}
console.info('finished loading:', path);
}
/>
);
}
Here, I want to check if props value is available for abc or pqr and then it should assign that value. How do I code better?
Any suggestion appreciated.
Aucun commentaire:
Enregistrer un commentaire