From f63caeef8f28a42a9996ab1b34633bb00dc0001a Mon Sep 17 00:00:00 2001 From: seoyoung-min Date: Sat, 3 Feb 2024 03:31:10 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20CreatePortal=20=EC=9E=84=ED=8F=AC?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F?= =?UTF-8?q?=20=ED=8F=AC=ED=83=88=20=EC=84=B1=EB=8A=A5=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ModalPortal.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/ModalPortal.ts b/src/components/ModalPortal.ts index 48937fab..3586b621 100644 --- a/src/components/ModalPortal.ts +++ b/src/components/ModalPortal.ts @@ -1,14 +1,18 @@ import { ReactNode } from 'react'; -import ReactDOM from 'react-dom'; +import { createPortal } from 'react-dom'; interface Props { children: ReactNode; } const ModalPortal = ({ children }: Props) => { + if (typeof window === 'undefined') { + return null; + } + const el = document.getElementById('modal-root') as HTMLElement; - return ReactDOM.createPortal(children, el); + return createPortal(children, el); }; export default ModalPortal;