Untitled
Anonymous
plain_text
01/03/2024 2:10 AM
696 B
23
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