mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-27 11:02:16 +01:00
20 lines
567 B
TypeScript
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;
|
|
};
|