React · Junior · Question 5 of 75

Why can't you write {if (isAdmin) { <Admin /> }} inside JSX?

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.

Further reading

Problem with a question

React · Junior · question 5

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz