Complete the code to render a message only if the user is logged in.
function Greeting({ isLoggedIn }) {
return (
<div>
{isLoggedIn && [1]
</div>
);
}Using isLoggedIn && <p>Welcome back!</p> shows the message only when isLoggedIn is true.
Complete the code to show 'Loading...' text while data is being fetched.
function DataLoader({ isLoading }) {
return (
<div>
{isLoading ? [1] : <p>Data loaded</p>}
</div>
);
}The ternary operator shows <p>Loading...</p> when isLoading is true, otherwise shows 'Data loaded'.
Fix the error in the code to conditionally render a button only if the user is an admin.
function AdminButton({ isAdmin }) {
return (
<div>
{isAdmin && [1]
</div>
);
}The correct JSX for a button includes opening and closing tags: <button>Delete User</button>.
Fill both blanks to render a message if user is logged in and show a logout button.
function UserPanel({ isLoggedIn }) {
return (
<div>
{isLoggedIn ? [1] : [2]
</div>
);
}When logged in, show welcome message; otherwise, ask to log in.
Fill all three blanks to render a list of items only if the list is not empty, otherwise show 'No items'.
function ItemList({ items }) {
return (
<div>
{items.length > 0 ? (
<ul>
{items.map([1] => (
<li key=[2]>[3]</li>
))}
</ul>
) : (
<p>No items</p>
)}
</div>
);
}Use item as the map parameter, item.id as the key, and item.name as the displayed text.