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

21 lines
432 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-08-27 16:35:17 +03:00
useClickedOutside({ ref, callback: () => setIsActive(false) })
2023-07-25 20:27:29 +03:00
2023-07-20 17:11:03 +03:00
return {
2023-07-25 20:27:29 +03:00
ref,
isActive,
setIsActive,
2023-08-27 16:35:17 +03:00
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;