Skip to content

Commit

Permalink
modify: useOutsideClick 훅 callback 사용성 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
JitHoon committed Jan 19, 2024
1 parent 0e6769d commit 0fc1c46
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CouponExpose = () => {
setIsRoomList(!isRoomList);
};

useOutsideClick(roomListRef, setIsRoomList);
useOutsideClick(roomListRef, () => setIsRoomList(false));

return (
<CouponContainer $isToggle={isToggle}>
Expand Down
5 changes: 2 additions & 3 deletions src/components/common/Layout/Header/User/UserModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { getCookies } from '@utils/lib/cookies';
import theme from '@styles/theme';

const UserModal = ({ isOpen, setIsUserModalOpen }: UserModal) => {
const modalRef = useRef<HTMLDivElement>(null);
const userName = getCookies('userName');
const userEmail = getCookies('userEmail');

const modalRef = useRef<HTMLDivElement>(null);

useOutsideClick(modalRef, setIsUserModalOpen);
useOutsideClick(modalRef, () => setIsUserModalOpen(false));

return (
<Modal
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/lib/useOutsideClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { RefObject, useEffect } from 'react';

const useOutsideClick = <T extends HTMLElement>(
ref: RefObject<T>,
setter: React.Dispatch<React.SetStateAction<boolean>>
setter: () => void
): void => {
const handleClickOutside = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) {
setter(false);
setter();
}
};

Expand All @@ -33,7 +33,7 @@ const YourComponent = () => {
const [isOpen, setIsOpen] = useState(false);
const modalRef = useRef(null);
useOutsideClick(modalRef, setIsOpen);
useOutsideClick(modalRef, () => setIsOpen(boolean));
// ...
Expand Down

0 comments on commit 0fc1c46

Please sign in to comment.