Conditional Rendering
Conditional rendering is showing different JSX depending on a condition, such as displaying a 'Log out' button only when a user is signed in. React uses ordinary JavaScript logic to decide what to render.
React
Because JSX is just JavaScript, you control what appears using normal tools: if-statements, the ternary operator (condition ? a : b), and the logical AND (condition && jsx). The ternary is handy for choosing between two outputs, while && renders something only when a condition is true.
Returning null from a component (or from a branch) tells React to render nothing. A common beginner gotcha: using && with a number like {count && <p>...</p>} can accidentally print 0, so prefer a real boolean such as {count > 0 && ...}.
Examples
JSX — Renders 'Welcome back!' when loggedIn is true and 'Please log in.' when it is false.
function Status({ loggedIn }) {
return (
<div>
{loggedIn ? <p>Welcome back!</p> : <p>Please log in.</p>}
</div>
);
}