Untitled

 avatar
user_1905141
plain_text
a month ago
534 B
1
Indexable
Never
  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