React · Junior · Question 52 of 75
How do you render one of two elements depending on a condition?
- ✓Correct answer: With a ternary:
{isLoggedIn ? <Profile /> : <LoginButton />} - 2With
<if condition={isLoggedIn}> - 3With a
switchstatement directly inside JSX
Explanation
JSX accepts expressions, so ? : works inline. For several branches, compute the element in a variable or a helper function before return.