call(back)
FrontendmediumSign in to star problems

Build an Accordion

Build an accordion from the provided SECTIONS data. The starter renders every section expanded — make each one toggle on its own.

Requirements

  • Clicking a section's title expands or collapses that section.
  • Sections toggle independently: any number can be open at once.
  • All sections start collapsed.
  • Keep aria-expanded on each title button in sync (the chevron flips off it).

Hints

Hint 1

Track open sections as a Set of ids in one state value; a section is open when the set has its id.

Hint 2

State must be replaced, not mutated: copy with new Set(open), then add or delete, then set the copy.

Hint 3

Collapse by not rendering the body (open.has(id) && <p>…</p>) — the aria-expanded attribute belongs on the button either way.

Asked at