ConceptPortal-public/rsconcept/frontend/src/hooks/useDropdown.ts

21 lines
447 B
TypeScript
Raw Normal View History

2023-07-20 17:11:03 +03:00
import { useRef, useState } from 'react';
2023-07-25 20:27:29 +03:00
2023-07-20 17:11:03 +03:00
import useClickedOutside from './useClickedOutside';
function useDropdown() {
const [isActive, setIsActive] = useState(false);
const ref = useRef(null);
2023-07-25 20:27:29 +03:00
useClickedOutside({ ref, callback: () => { setIsActive(false); } })
2023-07-20 17:11:03 +03:00
return {
2023-07-25 20:27:29 +03:00
ref,
isActive,
setIsActive,
toggle: () => { setIsActive(!isActive); },
hide: () => { setIsActive(false); }
2023-07-20 17:11:03 +03:00
};
}
2023-07-20 17:11:03 +03:00
2023-07-25 20:27:29 +03:00
export default useDropdown;