I am trying to write a quiz type module where you can select one of two answers.
const [active, setActive] = useState(true);
const toggle = () => {
setSelected(!selected)
}
<div id="quizAnswers">
<div className="answer {active ? 'active' : ''}">
{quiz.answers[0].text}
<button label="{active ? 'ACTIVE' : 'inactive'}" onClick={toggle}>
{active ? "ACTIVE" : "inactive"}
</button>
</div>
<div className="answer {active ? 'active' : ''}">
{quiz.answers[1].text}
<button label="{active ? 'ACTIVE' : 'inactive'}" onClick={toggle}>
{active ? 'ACTIVE' : 'inactive'}
</button>
</div>
This is about as far as I can figure out how to get. I am trying to get it so that when I click one button, the label and text switch to active, while switching the other to inactive, if it is currently active.
I've seen some stuff with react-DOM but I'm wondering if there is a more straight forward way to accomplish this? Thanks in advance.