I have a Set collection of values. I want to iterate over these and render a component for each value.
I understand I can't use forEach() as I need to return something which is why map() is highly recommended.
But again I have a Set and not an Array.
I could use Array.from(set) but it no longer rerenders when the Set state changes, even though I could very well see that the state has indeed changed.
What would be the cleanest way to map() over the values of a Set collection in a state?
...
const [selected, setSelected] = useState(new Set([]))
const addToSelected = data => {
setSelected(state => state.add(data))
console.log(selected)
}
render(
{selected &&
Array.from(selected).map(data => {
return (
<QuestionsItem
key={data.message}
data={data}
negative
callback={removeSelected}
/>
)
})}
)