vendredi 13 août 2021

Writing if else condition function in inline code doesn't return any value

Why does this method doesn't return any value?

<span>{()=>{
    if(profile.age){
        return (2021 - profile.age)
    }
}}</span>

Aren't this the same as when you create a different function and call it like this?

<span>{renderAge()}</span>

function renderAge(){
    if(profile.age){
        return (2021 - profile.age)
    }
}

I know I can do the inline condition using ? : but if I have multiple conditions it would be hard and also I don't want to create a separate function for that.

Aucun commentaire:

Enregistrer un commentaire