Untitled

 avatar
unknown
plain_text
a year ago
534 B
3
Indexable
 const myFilter = products.filter(el =>
      el.name.toLowerCase().includes(filterText.toLowerCase()) &&
      (inStockOnly ? el.stocked : true || !inStockOnly)
    );
    const finalList = myFilter.reduce((a, c) => {
      const isCategoryChanged = c.category !== a.lastCategory;
      a.output = [...a.output, isCategoryChanged && <ProductCategoryRow key={c.category} category={c.category} />, <ProductRow key={c.name} product={c} />];
      a.lastCategory = c.category;
      return a;
    }, { lastCategory: null, output: [] }); 
Leave a Comment