I am trying to display an array within another array and I am not sure how.
Here is my code:
interface QuestionHeader {
id: number;
questionName: string;
question: Question;
}
interface Question {
id: number;
questionContent: string;
isSelected: false;
}
export default function Questions() {
const [questions, setQuestions] = useState<QuestionHeader[]>([]);
useEffect(() => {
const requestOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
};
fetch(`URL`, requestOptions)
.then(res => res.json())
.then(e => {
setQuestions(e)
});
},[])
return (
<div style={{ textAlign: "center" }}>
<div>
<ul>
{questions.map(item=>{
return (<li>{item.questionName}{item.question.map(q=> )}</li>
);
})}
</ul>
...
When I try to do item.map or item.question.map, I get an error that map does not exist in type Question.