const Modal = ({ children, onClose }: ModalProps): JSX.Element => {
useEffect(() => {
document.body.style.overflow = 'hidden';
return () => {
document.body.style.overflow = 'unset';
};
}, []);
return (
<Wrapper>
<Overlay onClick={onClose} />
<ModalContent>
...
{children}
</ModalContent>
</Wrapper>
);
};
useEffect hook
Wrapper
export const Wrapper = styled.div`
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
background-color: rgb(0, 0, 0, 0.6);
`;
Overlay
export const Overlay = styled.div`
position: absolute;
width: 100%;
height: 100%;
`;