I coding an app which you get a question with 4 multiple choices , one of them is correct and the other three are false , if the user click on the correct answer the background of that element turns green , otherwise it turns red , i was figuring out a away how to do it useing a 2 useState hook , one if case the answer is correct the other of the answer is wrong , i also used useRef to extract the value from the elemnt and compare it to the correct answer in the ChoosenOption function , how i can switch between different background colors using the useState i mentioned above , or anybetter ways to do this it will be much appreciated.
Hi,
Thank you , as you see from my code i already created a function called (ChoosenOption) , i have already passed to the ClassName attribute but seems like it doesnt work , so i was in doubt if its correct to do it this way?
I can’t see where you’ve tried what I’ve suggested. This is a standard technique that I have used countless times so I’m reasonably sure it works.
Here as a pen where you can mess around with it yourself.