1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00
unleash.unleash/frontend/src/component/layout/MainLayout/NavigationSidebar/useExpanded.ts
2024-05-27 16:29:20 +02:00

20 lines
567 B
TypeScript

import { useLocalStorageState } from 'hooks/useLocalStorageState';
import { unique } from 'utils/unique';
export const useExpanded = <T extends string>() => {
const [expanded, setExpanded] = useLocalStorageState<Array<T>>(
'navigation-expanded:v1',
[],
);
const changeExpanded = (key: T, expand: boolean) => {
if (expand) {
setExpanded(unique([...expanded, key]));
} else {
setExpanded(expanded.filter((name) => name !== key));
}
};
return [expanded, changeExpanded] as const;
};