Skip to content

Commit

Permalink
fix: 컴포넌트 자체 상태값 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevile committed Jul 26, 2024
1 parent f6771dc commit 80cbf5b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/web-domains/src/common/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export interface ModalProps extends HTMLAttributes<HTMLDivElement> {
}

export const Modal = ({ isOpen, width, onClose, children, footer, ...rest }: PropsWithChildren<ModalProps>) => {
const [modalState, setIsModalState] = useState<boolean>(isOpen);
const [element, setElement] = useState<HTMLElement | null>(null);

const modalWidth = width ? `${width}px` : '100%';

const handleClose = () => {
setIsModalState(false);
onClose?.();
};

Expand All @@ -27,7 +25,7 @@ export const Modal = ({ isOpen, width, onClose, children, footer, ...rest }: Pro
}, []);

useEffect(() => {
if (modalState) {
if (isOpen) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = 'auto';
Expand All @@ -36,7 +34,7 @@ export const Modal = ({ isOpen, width, onClose, children, footer, ...rest }: Pro
return () => {
document.body.style.overflow = 'auto';
};
}, [modalState]);
}, [isOpen]);

if (typeof window === 'undefined') {
return <></>;
Expand All @@ -46,7 +44,7 @@ export const Modal = ({ isOpen, width, onClose, children, footer, ...rest }: Pro
return <></>;
}

if (!modalState) {
if (!isOpen) {
return null;
}

Expand Down

0 comments on commit 80cbf5b

Please sign in to comment.