Untitled
unknown
plain_text
2 years ago
522 B
11
Indexable
const myFilter = products.filter((el) =>
el.name.toLowerCase().includes(filterText.toLowerCase()) &&
(!inStockOnly || (inStockOnly && el.stocked))
);
const finalList = myFilter.reduce((a, c) => {
const isNewCategory = c.category !== a.lastCategory;
if (isNewCategory) {
a.output.push(<ProductCategoryRow key={c.category} category={c.category} />);
a.lastCategory = c.category;
}
a.output.push(<ProductRow key={c.name} product={c} />);
return a;
}, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment