Untitled
user_7164856
plain_text
2 years ago
547 B
24
Indexable
const myFilter = products.filter(el => el.name.toLowerCase().includes(filterText.toLowerCase()) &&(!inStockOnly || el.stocked)); // console.log(myFilter) const finalList = myFilter.reduce( (a,c) => { if(c.category !== a.lastCategory) { a.output = [...a.output, <ProductCategoryRow key={c.category} category={c.category} />] a.lastCategory = c.category } a.output = [...a.output, <ProductRow key={c.name} product={c}/>] return a },{lastCategory:null, output: []}) // console.log(finalList)
Editor is loading...
Leave a Comment