springload / react-accessible-accordion

Accessible Accordion component for React
https://springload.github.io/react-accessible-accordion
MIT License
787 stars 113 forks source link

how to re render Accordion to make it expandable automatically on state change #371

Open saloni-dhiwise opened 2 months ago

saloni-dhiwise commented 2 months ago

I am having difficulties expanding the accordian item as soon as state change

This is my state const [expandedItems, setExpandedItems] = React.useState<string[]>(['item-0']);

This is my element <Accordion className='flex flex-col' preExpanded={expandedItems} onChange={(expanded: string[]) => { setExpandedItems(expanded); }} allowZeroExpanded allowMultipleExpanded>

This is how I am updating the state if (!expandedItems.includes(`item-${index}`)) { setExpandedItems([...expandedItems, `item-${index}`]); }

Item <AccordionItem className='flex flex-col gap-3 px-3 py-4 border-t border-grey-base03' key={index} uuid={`item-${index}`}>

saloni-dhiwise commented 2 months ago

State is getting updated as I logged it, but Item is not getting auto expanded as soon as state gets updated