diff --git a/src/hook/useCalculateInnerWidth.ts b/src/hook/useCalculateInnerWidth.ts new file mode 100644 index 0000000..1d046a5 --- /dev/null +++ b/src/hook/useCalculateInnerWidth.ts @@ -0,0 +1,21 @@ +import { useEffect, useState } from 'react'; + +const useCalculateInnerWidth = () => { + const [windowWidth, setWindowWidth] = useState(window.innerWidth); + + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, []); + + return windowWidth; +}; + +export default useCalculateInnerWidth;