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; diff --git a/src/hooks/useBooleanOutput.ts b/src/hooks/useBooleanOutput.ts index b1da56c9..659a752b 100644 --- a/src/hooks/useBooleanOutput.ts +++ b/src/hooks/useBooleanOutput.ts @@ -8,7 +8,7 @@ interface useBooleanOutput { } export default function useBooleanOutput(defaultValue?: boolean): useBooleanOutput { - const [isOn, setIsOn] = useState(!!defaultValue); + const [isOn, setIsOn] = useState(!!defaultValue); const toggle = useCallback(() => setIsOn((prev) => !prev), []); const handleSetOn = useCallback(() => setIsOn(true), []); diff --git a/src/hooks/useOnClickOutside.ts b/src/hooks/useOnClickOutside.ts index 615cd647..07976fbf 100644 --- a/src/hooks/useOnClickOutside.ts +++ b/src/hooks/useOnClickOutside.ts @@ -1,4 +1,4 @@ -import { EventHandler, useEffect, useRef, useState } from 'react'; +import { useEffect, useRef } from 'react'; const useOnClickOutside = (handler: () => void) => { const ref = useRef(null); @@ -15,7 +15,7 @@ const useOnClickOutside = (handler: () => void) => { document.removeEventListener('mousedown', handleClickOutside); document.removeEventListener('touchstart', handleClickOutside); }; - }, [ref]); + }, [ref, handler]); return { ref }; };