Untitled

 avatar
SWKP
plain_text
a month ago
620 B
0
Indexable
Never
const myFilter = products.filter(el => {
    const isMatching = el.name.toLowerCase().includes(filterText.toLowerCase());
    const isStockMatch = (inStockOnly && el.stocked) || (!inStockOnly);
    return isMatching && isStockMatch;
  });

    const finalList = myFilter.reduce((a, c) => {
    const isNewCategory = c.category !== a.lastCategory;
    a.output = [...a.output,...(isNewCategory ? [<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