UNPKG

quantumai-design-system

Version:

퀀텀에이아이의 디자인 시스템

17 lines (16 loc) 688 B
import { useEffect, useState } from 'react'; export function useOutsideClose(ref, notOutSideClose) { var _a = useState(false), selectShow = _a[0], setSelectShow = _a[1]; useEffect(function () { function handleInteraction(event) { if (notOutSideClose && (ref === null || ref === void 0 ? void 0 : ref.current) && !ref.current.contains(event.target)) { setSelectShow(false); } } document.addEventListener('click', handleInteraction); return function () { document.removeEventListener('click', handleInteraction); }; }, [ref, notOutSideClose]); return [selectShow, setSelectShow]; }