Last active
March 15, 2022 12:44
-
-
Save koalicioous/af4ead367cd5f335a7650233b5022e16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Question = { | |
question: string, | |
answer: string | |
} | |
type FAQSection = { | |
title: string, | |
items: Question[] | |
} | |
const FAQ: FAQSection[] = [ | |
{ | |
title: 'Seputar Covid', | |
items: [ | |
{ | |
question: 'Siapa nama kamu?, | |
answer: 'Sebuah Nama', | |
}, | |
{ | |
question: 'Kapan kamu dilahirkan?, | |
answer: 'Misalnya ini adalah sebuah tanggal', | |
}, | |
//...restOfQuestions | |
] | |
}, | |
//...restOfSections | |
] | |
const QuestionItem = (item: Question) => { | |
return ( | |
<div> | |
<h2>{item?.question}</h2> | |
<p>{item?.answer}</p> | |
</div> | |
) | |
} | |
const FAQSection = (title: string, items: Question[]) => { | |
return ( | |
<section> | |
<h1>{ title }</h1> | |
<div> | |
{ | |
items?.length > 0 && | |
items.map((item) => { | |
return <QuestionItem item={item} /> | |
}) | |
} | |
</div> | |
</section> | |
) | |
} | |
FAQ.map((section,idx) => { | |
return ( | |
<FAQSection | |
title={section.title} | |
items={section.items} | |
/> | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment