React · Junior · Question 5 of 75
Why can't you write {if (isAdmin) { <Admin /> }} inside JSX?
- ✓Correct answer: Only expressions are allowed in curly braces, and
ifis a statement - 2Because React replaced
ifwith a special<If>component - 3You can, but only inside class components
Explanation
Inside {} you can put any JS expression that produces a value: a variable, a function call, a ternary cond ? a : b, cond && a. Statements (if, for) are used outside JSX - before return or in a separate function. React has no <If> component.