Add a search box to the product list page that filters by name. When an operator types a query, show only the products whose name contains that text (partial match). If the query is empty, show all products. Complete filterProducts(products, query).
Add a name-based search to a React product list page. When a query is typed, show only the products whose name contains that text (partial match); when the query is empty, show all products. The search/filter logic lives in a pure function in lib/filter-products.ts, and the page only calls it.
A search filter narrows a full list down to the items that match a query. This problem filters on a single field β the product name β by partial match, and shows everything when the query is empty. Keeping the filter logic in a pure function separate from the screen means the same input gives the same result, which makes it easy to test. What makes the behavior trustworthy is verifying not just matching cases but boundary cases too, such as an empty query and a query that matches nothing.