HTML
4
Вклад в тег
useEffect(() => {
if (setColorFilter) {
sortItems()
}
}, [colorFilter, sortItems])
const sortItems = useCallback(() => {
let tempItems = [...items];
// -----> Filter by colors
if (colorFilter) {
tempItems = tempItems.filter(item => item.color.includes(colorFilter));
}
setFilteredItems(tempItems);
console.log(`items are sorted. new array has ${tempItems.length} items`)
}, [colorFilter, items])