Let's say I have this faq array as one of my states:
this.state = {
faqs: [
{
section: "Section One",
faqList: [
{
question: "Q1",
answer: "A1"
},
{
question: "Q1",
answer: "A1"
}
]
},
{
section: "Section Two",
faqList: [
{
question: "Q1",
answer: "A1"
},
{
question: "Q1",
answer: "A1"
}
]
}
]
}
And I'd like to render them. This is how I tried to do it currently:
render() {
const faqs = this.state.faqs;
return (
<div>
{faqs.map(faqSec => {
return (
<h2>{faqSec.section}</h2>
{faqSec.faqList.map(faq => {
return (
<p>faq.question</p>
<p>faq.answer</p>
)
})}
)
})}
</div>
);
}
However, an error occurs due to the nested map function:
SyntaxError: Unexpected token, expected , (80:8)
How do I loop through this nested object properly?