← BYTES
React.js·Starter·Ref: 4.1.14

Which of these is a correct way to conditionally render JSX in React?

Have a question about this video? Mention reference 4.1.14 when you contact us.

a.Using an `if` statement directly inside the returned JSX markup
b.Conditional rendering is not possible in React
c.Using a ternary expression or the `&&` operator inside the JSX, e.g. `{isLoggedIn && <Welcome />}`
d.By wrapping the component in a `<Conditional>` built-in HTML tag
Because JSX is just JavaScript expressions, you can't drop a bare `if` statement directly inside the markup, but you can use expressions like ternaries (`cond ? a : b`) or short-circuiting `&&` to choose what gets rendered.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES4114#Reactjs