Part 04 / Topic 7 of 8
Filtering a list
.filter() - another plain-JS array method this course's prerequisites assume - picks out the subset of an array worth rendering; .map() then only ever sees that subset. The two combine as a pipeline, re-run on every render with whatever the current filter value is:
// examples/04_menu_browser.jsx (trimmed)
const [query, setQuery] = useState("");
const visibleItems = items.filter((item) => item.name.toLowerCase().includes(query.trim().toLowerCase()));
useState and the controlled <input>'s onChange here are exactly Part 3's hooks and event handling, used as that part introduces them - nothing new in how the input works, only what its value now drives. .filter() runs fresh on every render, so visibleItems is always in sync with whatever query currently holds; there is no separate "filtered list" state to keep up to date by hand.
Done here? The practice set for Part 4 — including the solutions — is on the part page.