I am trying to push my querySelectorAll .map function to a React State Array but its not working as expected.
const [affectedServices, setAffectedServices] = useState([]);
function affectedTags() {
Array.from(document.querySelectorAll(".active-tag")).map((tag) => {
console.log(tag.innerHTML);
setAffectedServices([tag.innerHTML]);
});
}
console.log(tag.innerHTML) will display all querySelected tags e.g.
Active tag 1
Active tag 2
Active tag 3
But when viewing the affectedServices state from React Dev tools, it only has one array which contains Active tag 3
Any ideas of what im doing wrong?
TIA