Untitled
const finalList = products .filter(el => ( el.name.toLowerCase().includes(filterText.toLowerCase()) && (inStockOnly ? el.stocked : true) )) .reduce((a, c) => { if (c.category !== a.lastCategory) { 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: [] });
Leave a Comment