Accordion — Only One Section Open at a Time

Hooks & State — Beginner React challenge.

Build a classic FAQ-style accordion where clicking a section's header expands its content — but opening a new section always closes whatever was open before. Only one section can ever be expanded at once.

Requirements

Signature

function Accordion({ sections }: { sections: { id: number; title: string; content: string }[] }): JSX.Element

Example

<Accordion sections={[{ id: 1, title: "Q1", content: "A1" }, { id: 2, title: "Q2", content: "A2" }]} />
// click Q1's header ⇒ A1 shows
// click Q2's header ⇒ A1 hides, A2 shows
// click Q2's header again ⇒ A2 hides, nothing open

Constraints

🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code
Loading workspace…