Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
467 B
5
Indexable
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