'How can react quiz maker work with question array
I'm using the react native quiz maker (https://github.com/jtalz/react-native-quiz-maker) to make a quiz, and I currently have an array that has all questions in the specified format. However, when I use the below code to display the quiz, I get empty space where the quiz should been. I have a feeling it may be because they require questions = {[{question 1}{question 2}]} where the array is in curly brackets, whereas I simply try to use an array. However, when I tried questions = {{questionList}} I get Uncaught TypeError: Invalid attempt to spread non-iterable instance. Any workaround for this?
Here's my code currently, where I have a list of objects, and I put them in into the required question format with a for loop. So, I have questionList, which is an array of objects, where each one is formatted according to quiz maker's format (this part works perfectly, when I try to console.log, I get the output I want)
function Home ({route}) {
let questionList = [];
for (let x = 0; x < subset.length; x++) {
if (route.params.name == 'StoE') {
let question = {
questionType: 'Writing',
question: `What is '${subset[x].spanish}' in English?`,
answer: subset[x].english
}
questionList.push(question)
} else {
let question = {
questionType: 'Writing',
question: `What is '${subset[x].english}' in Spanish?`,
answer: subset[x].spanish
}
questionList.push(question)
}
}
return (
<View style={global.container}>
<Text>{route.params.name}</Text>
<QuizContainer
questions={{questionList}}
onSubmit={(isCorrect) => console.log(isCorrect)}
onComplete={(progress) => console.log('score: ', progress)}
/>
{console.log(questionList)}
</View>
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
