Пример кода?
filterCategories (categories, isParentCategoryActive = false) {
if (!categories) {
return null
}
const { activeCategoryId } = this.props.presentations;
return categories.map((category) => {
if (!category) {
return null
}
if (category.id === activeCategoryId || !activeCategoryId || isParentCategoryActive) {
if (category.id === activeCategoryId) {
this.setState({
categoryName: category.category
})
}
if (category.subcategories && category.subcategories.length) {
if(category.presentations && category.presentations.length) {
return category.presentations.concat(this.filterCategories(category.subcategories, true))
}
return this.filterCategories(category.subcategories, true)
} else if (category.presentations && category.presentations.length) {
return category.presentations;
}
return null;
}
return this.filterCategories(category.subcategories)
}).flat().filter(presentation => presentation)
}
categories - дерево, с бесконечно возможной вложенностью subcategories, на каждом уровне могут быть presentations