I am trying to understand the concept of writing expression in JSX but unable to understand that how is not javascript in curly braces an expression?
const Welcome()=>{
const isLoggedIn = true;
return(
<div>
{
if(isLoggedIn){
<p>Welcome!</p>
}else{
<p>Please Login</p>
}
}
</div>
);
}
Please guide me either when we assign a value isLoggedIn is true then validation happens, if value is true then it prints Welcome otherwise please log in.
Please tell me how is this a statement and not an expression.
ifstatements in JavaScript are statements, not expressions (unlike, say Kotlin). Use a ternary operator or&& ||instead. See developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…let a = 1 + 2because1 + 2is an expression. However you cannot dolet a = if (1) {2}becauseif (1) {2}is not an expression.