I have a some state like this :
const [tags, setTags] = useState([{id: 1, label: "random"}, {id: 2, label: "important"}])
const [input, setInput] = useState("")
const [selectedTag, setSelectedTag] = useState([])
and below that somewhere i have a function like this :
const addTag = (id: number)=> {
tags.map(tag => {
if(tag.id === id){
setSelectedTag(tag) // trouble here
}
})
}
I want to push the new selected tag into the state of selectedTags which is an array, how do i push the tag into that array when i can't even access selectedTags state directly?