I want to filter the results from my store in React-Redux. Therefor I have created a filter selector.
My code only returns all the "shoppers", while it should only be returning the filtered shoppers.
Each shopper has an array of reviews that contains (one or more) objects with the review (text) and review number. We want to filter on the review number. See printscreen:
So to clarify, I want to filter by the reviews of a shopper and if that number >= the filter to then return only the shoppers that match this criteria.
What am I doing wrong here? How can I get it to return only the filtered results?
export const selectShoppersWithFilters = (filters) => (state) => {
let shoppers = [...state.publicShoppers];
if (filters.minAverageReview) {
return shoppers.filter((shopper) => {
return shopper.reviews.map((review) => {
if (review.review >= filters.minAverageReview) {
return (shoppers = shopper);
}
});
});
}
console.log(shoppers);
return shoppers;
};
ps. bear with me, I'm a junior developer...