I have an accordion that works the way I need it to, except for one thing. After clicking on one of the accordion items, if another one that is collapsed is clicked, the one that was opened will close, but the one that was just clicked will not open.
Can anyone spot the problem in my code?
const [activeAccordion, setActiveAccordion] = useState(-1);
const handler = (index) => {
setActiveAccordion(currentItem => currentItem === -1 ? index : -1);
};
// relevant section of code below...
{ items.map((e, c) => {
return (
<div key={`key${c}`}>
<button className={styles.accordionButton} onClick={() => handler(c)}>
{e.name}
</button>
{activeAccordion === c &&
<div className={`${styles.accordionContent}`}>