Filter google maps markers on option selected

Viewed 90

I'm trying to filter my markers by categories based on a select so whenever a user choose one category the map should only show those markers with the same category, I did something and it worked half of the time because some of the markers were not refreshing on option selected:

const [filtereds, setFiltereds] = useState([])

const searchCategories = (selected) => {
    setFiltereds([])
    if(isSelected){
        bidders.map(item => item.categories.filter(categories => 
            {
                return categories.Category === selected ? setFiltereds((prevState) => [...prevState, item]) : console.log("")
            }))
        }
    console.log(filtereds)
}

I would like to do this in a different way if it's possible, what I did here is filter them before passing them to the maps component.

Here is where I handle the selected option:

const selectedOption = (opt) => {
    console.log("Option: ",opt);
    //maybe can I filter them here?
}
0 Answers
Related