3 回答
TA贡献1921条经验 获得超9个赞
{this.state.questionBank.length > 0 && this.state.questionBank.map( ({question,answer,correct,questionId}) => ( ) ) } –
这里的答案应该是 QuizService 中定义的答案
这是正确的 QuestionBox 道具
{this.state.questionBank.length > 0 && this.state.questionBank.map( ({question,answers,correct,questionId}) => ( ) ) } –
TA贡献1815条经验 获得超6个赞
我收到此错误是因为在渲染options时未定义。QuestionBox你应该试试这个:
import React, {useState} from "react";
const QuestionBox = ({question, options = [], selected}) => {
const [answer, setAnswer] = useState(options);
return (
<div className="questionBox">
<div className="question">{question}</div>
{answer && answer.map((text, index) => (
<button
key={index}
className="answerBtn"
onClick={() => {
setAnswer([text]);
selected(text);
}}
>
{text}
</button>
))}
</div>
);
};
export default QuestionBox;
添加回答
举报