I can't figure out what is wrong . Basically there is a filter component that passes either low or high value and the product is meant to change based on the value. The first value change works but after that, the Cardlist products props doesn't change
function ProductOverview({products, history}) {
let [productsValue, setProducts] = useState(products);
const setFilter = (value) => {
let sortedProduct;
if (value === 'low'){
sortedProduct = products.sort((a, b) => a.price - b.price)
setProducts(sortedProduct);
}
else if (value ==='high'){
console.log("higg")
sortedProduct = products.sort((a, b) => b.price - a.price)
setProducts(sortedProduct)
}
};
return (
<div className="product-overview">
<Filter setValue={setFilter} />
{products.length > 0 ? (
<CardList products={productsValue} />
) : (
<div className="empty-list">No Item</div>
)}
</div>
);
}