mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
33 lines
713 B
TypeScript
33 lines
713 B
TypeScript
|
import { useCallback, useState } from "react";
|
||
|
|
||
|
interface IUseToggleSidePanelHook {
|
||
|
isSidePanelOpen: boolean;
|
||
|
toggleSidePanel: () => void;
|
||
|
setSidePanelOpen: (isOpen: boolean) => void;
|
||
|
}
|
||
|
|
||
|
const useToggleSidePanel = (
|
||
|
initialIsOpened: boolean
|
||
|
): IUseToggleSidePanelHook => {
|
||
|
const [isSidePanelOpen, setIsOpen] = useState<boolean>(initialIsOpened);
|
||
|
|
||
|
const toggleSidePanel = useCallback(() => {
|
||
|
setIsOpen(!isSidePanelOpen);
|
||
|
}, [setIsOpen, isSidePanelOpen]);
|
||
|
|
||
|
const setSidePanelOpen = useCallback(
|
||
|
(isOpen: boolean) => {
|
||
|
setIsOpen(isOpen);
|
||
|
},
|
||
|
[setIsOpen]
|
||
|
);
|
||
|
|
||
|
return {
|
||
|
isSidePanelOpen,
|
||
|
toggleSidePanel,
|
||
|
setSidePanelOpen,
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export default useToggleSidePanel;
|