Part 04 / Topic 6 of 8
Empty states
A list that can be filtered, searched, or start with zero items needs a deliberate branch for "there is nothing to show" - the alternative, a blank <ul></ul>, looks identical to a loading screen or a broken one from a user's point of view. This is a ternary at the list's root, not inside each item:
// examples/04_menu_browser.jsx (trimmed)
{visibleItems.length === 0 ? (
<p className="empty-state">{`No dishes match "${query}".`}</p>
) : (
<ul>{visibleItems.map((item) => <li key={item.id}>...</li>)}</ul>
)}
visibleItems.length === 0 is deliberately a comparison, not !visibleItems.length - section 5 just showed why trusting a number's truthiness directly is the exact trap to avoid, even in a condition that happens to control an if/ternary rather than JSX output directly. Section 7 shows this empty state actually appearing once a search matches nothing.
Done here? The practice set for Part 4 — including the solutions — is on the part page.