So I have an array of items that are randomly displayed:
const questions = this.state.questions
.sort(() => Math.random() - Math.random())
.find(() => true);
And I have a button. If I click on this button, I want to put the content of the displayed item:
{questions && (
<div>
<div className="questions-card">
{questions.question}
</div>
<div>
<Button
onClick={() =>
this.setState({
question: questions.question,
})
}
>
Answer
</Button>
</div>
</div>
)}
I don't know why, but every time I click on this button, it skips to the next item. I don't want this. All I want is to put questions.question
in the state. What's going on?