trying to make a dynamic filter, it reads the array and returns a button that then filters the data rendered. I'm trying to get it to only show unique filters though and cant figure out how. My current code:
const typeFilter = data?.venuesByCountry.map(v => (
v.venueTypes.map(a =>(
<>
<Button onClick={() => filterC(`${a}`)}>{a}</Button>
</>
))
))
returns:
["VENUE"]
["RESTAURANT"]
["BAR", "DRINKS", "PUB"]
["BAR", "DRINKS"]
["BAR", "DRINKS"]
But I want it to return something like:
["VENUE"]
["RESTAURANT"]
["BAR"]
["DRINKS"]
["PUB"]
or:
["VENUE"]
["RESTAURANT"]
["BAR", "DRINKS", "PUB"]
any help would be much appreciated!
edit
Here's the solution I went with:
const typeFilter = data?.venuesByCountry.reduce((acc, item) => {
item.venueTypes.forEach(v => {
(acc.indexOf(v) < 0) ? acc.push(v) : null })
return acc
}, []).map(a => (
<>
<Button $style={{marginRight:'6px'}} onClick={() => filterC(`${a}`)}>{a.toString().replace(/_/g, ' ')}</Button>
</>
))
Appreciate the fast reply's