I'm trying to make collapsible list in sidebar. On click i'm changing "isOpen" state and depending on this state I'm displaying or hiding sub links. The problem is that all sub links opening at same time .
Check sandbox here: https://codesandbox.io/s/infallible-moore-h16g6
const Sidebar = ({ title, children, data, opened, ...attrs }) => {
const [isOpen, setTriger] = useState(false);
const handleClick = idx => {
setTriger(!isOpen)
};
return (
<SidebarUI>
{data.map((item, idx) => {
return typeof item.data === "string" ?
<div key={idx} >{item.name}</div>:
<Fragment key={idx}>
<div onClick={() => handleClick(idx)}>{item.name}</div>
{ item.data.map((subs, ids) => {
return <Test isOpen={isOpen} key={ids}>++++{subs.name}</Test>;
})}
</Fragment>
})}
</SidebarUI>
);
};