Untitled

mail@pastecode.io avatar
unknown
javascript
2 months ago
556 B
16
Indexable
Never
const filteredProducts = products.filter(
    (pd) =>
    pd.name.toLowerCase().includes(filterText.toLowerCase()) &&
      (inStockOnly ? pd.stocked : true)
  );
  const finalList = filteredProducts.reduce(
    (rs, pd) => {
      if (pd.category !== rs.lastCategory) {
        rs.output.push(<ProductCategoryRow key={pd.category} category={pd.category} />);
        rs.lastCategory = pd.category;
      }
      rs.output.push(<ProductRow key={pd.name} product={pd} />);
      return rs;
    },
    { lastCategory: null, output: [] }
  );
Leave a Comment