React current elements class change code not working with setState

63 Views Asked by At

In my application I am using an ul and li tags and when one li is clicked the application is changing its background color with a class. I also wants to save the value of that li tag. I am trying to use setState hook with the class changing code but It seems its not working with each other. My code is

function store(e,q,a){
    const allElements = document.querySelectorAll('*')
    allElements.forEach(el => el.classList.remove('select'))
    e.currentTarget.classList.add('select');
    setCurquest({quest:q,ans:a});
   }

<li onClick={(e) => {checkAns(e,quest.Qid,ans.Content)}}>{ans.Content}</li>
0

There are 0 best solutions below