diff --git a/striker-ui/hooks/useWindowDimenions.ts b/striker-ui/hooks/useWindowDimenions.ts new file mode 100644 index 00000000..701ab917 --- /dev/null +++ b/striker-ui/hooks/useWindowDimenions.ts @@ -0,0 +1,19 @@ +import { useEffect, useState } from 'react'; + +const useWindowDimensions = (): number | undefined => { + const [windowDimensions, setWindowDimensions] = useState( + undefined, + ); + useEffect(() => { + const handleResize = (): void => { + setWindowDimensions(window.innerWidth); + }; + handleResize(); + window.addEventListener('resize', handleResize); + return (): void => window.removeEventListener('resize', handleResize); + }, []); // Empty array ensures that effect is only run on mount + + return windowDimensions; +}; + +export default useWindowDimensions;