Part 04 / Topic 8 of 8
Putting it together: a Rohan's Tiffin Center menu browser
examples/04_menu_browser.jsx combines every section above into one component: .map() over the filtered list with a stable item.id key (section 3's lesson, applied from the start instead of fixed after the fact), a ternary for each row's in-stock/out-of-stock button (section 4), and an empty state the moment a search matches nothing (sections 5–6).
// examples/04_menu_browser.jsx (trimmed)
<li key={item.id} className={item.inStock ? "" : "out-of-stock"}>
<span>{item.name}</span> <span>{`₹${item.price}`}</span>{" "}
<button disabled={!item.inStock}>{item.inStock ? "Add" : "Out of stock"}</button>
</li>
examples/04_menu_browser.test.jsx really drives this with @testing-library/user-event, typing into the search box exactly the way a visitor would:
1. Initial render, no search typed: all 4 dishes show. Veg Biryani's
button is disabled and reads "Out of stock"; the other 3 read "Add"
and are enabled.
2. Type "coffee" -> exactly 1 row ("Filter Coffee") remains visible.
3. Type "pizza" -> 0 rows remain; the empty state shows
`No dishes match "pizza".`
Every piece of this - the list, the key, the stock state, the search, the empty state - is a pattern from one of this part's earlier sections; nothing new is introduced in this section beyond wiring them together. The Stage 1 project (Menu Browser) grows this exact shape further: a category filter and an add-to-cart counter, on top of the list/key/filter/empty-state foundation this part just built.
Done here? The practice set for Part 4 — including the solutions — is on the part page.