Complete the code to render the component only if the user is logged in.
function App() {
const isLoggedIn = true;
return (
<div>
{isLoggedIn && [1]
</div>
);
}The expression {isLoggedIn && <Welcome />} renders the <Welcome /> component only when isLoggedIn is true.
Complete the code to render if the user is not logged in, otherwise render .
function App() {
const isLoggedIn = false;
return (
<div>
{isLoggedIn ? [1] : [1]
</div>
);
}The ternary operator chooses between <Dashboard /> and <Login />. Here, the first option is for when isLoggedIn is true.
Fix the error in the code to conditionally render only if user exists.
function App({ user }) {
return (
<div>
{user [1] <Profile user={user} />}
</div>
);
}The logical AND operator && renders <Profile /> only if user is truthy.
Fill both blanks to render if user is admin, else render .
function Dashboard({ user }) {
return (
<div>
{user.role [1] 'admin' ? [2] : <UserPanel />}
</div>
);
}The strict equality operator === checks if the role is 'admin'. If true, it renders <AdminPanel />, else <UserPanel />.
Fill all three blanks to create a dictionary of components to render based on status.
const statusComponents = {
success: [1],
error: [2],
loading: [3]
};This object maps status keys to their respective components for rendering.