Untitled

 avatar
unknown
javascript
a year ago
441 B
4
Indexable
const myFilter = products.filter( el => (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) && (!inStockOnly || el.stocked))

const finalList = myFilter.reduce( (a,c) => {
    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: []})
Editor is loading...
Leave a Comment