Accordion doesn't re-render when defaultIndex changed #8191
-
const currentModuleIndex = useMemo(() => {
if (modules) {
const index = Math.max(
modules.findIndex((module) => module._id === moduleId),
0
);
return index;
}
return 0;
}, [modules, moduleId]);
//....
<Accordion
display={{ base: 'none', md: 'block' }}
allowToggle
defaultIndex={currentModuleIndex}
>
{/*...*/}
</Accordion> Here is my code. When I think because I'm passing memo value to If I use Is there any solution for this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The Accordion
Hope this helps! |
Beta Was this translation helpful? Give feedback.
defaultIndex
is used to set the initial state for which accordion items are open.index
is used to set currently expanded accordion items and will re-render the component.The Accordion
onChange
function provides anexpandedIndex
. TheexpandedIndex
is the current accordion item index(es), which is a number ifallowMultiple
is off, or an array of numbers ifallowMultiple
is on. This can be used to store the changing index values to handle the index programmatically.-1
means all items are closed, and other numeric values are the index(es) of open accordion item(s).Hope this helps!