practicebasic
Accordion
An accordion component where each item can be expanded or collapsed independently. The state is a Set of open IDs.
Objectives
- 1.Declare
openItemsstate as an emptynew Set() - 2.In
toggleItem: ifidis in the Set, remove it; otherwise add it — always using a functional update with a copy - 3.Pass
openItems.has(item.id)as theisOpenprop to eachAccordionItem - 4.The
▼icon rotates 180° whenisOpenis true - 5.The content only renders when
isOpenis true
your code
Hint
Use a Set to store open IDs. To toggle: if set.has(id) delete it, otherwise add it. Always copy the Set before mutating.
Related concepts
Was this helpful?
Sign in to give feedback
