Conditional Rendering
Ternary Operator
const App = () => {
const num = 1;
return (
<div>
<p>
The number is {num % 2 === 0 ? "even" : "odd"}
</p>
</div>
);
};const LoginButton = () => {
return <button>Login</button>;
};
const LogoutButton = () => {
return <button>Logout</button>;
};
const App = () => {
const loggedIn = false
return (
<div>
{ loggedIn ? <LoginButton /> : <LogoutButton /> }
</div>
);
};Rendering Something Only When a Condition is true
truePrimitive Types JSX Won't Render
Last updated