Untitled
const finalList = products .filter(el => (el.name.toLowerCase().includes(filterText.toLowerCase())) && (!inStockOnly || (inStockOnly && el.stocked)) ) .reduce((output, product) => { const categoryRow = product.category !== output.lastCategory ? [<ProductCategoryRow key={product.category} category={product.category} />] : []; return { lastCategory: product.category, output: [...output.output, ...categoryRow, <ProductRow key={product.name} product={product}/>] }; }, { lastCategory: null, output: [] });
Leave a Comment