parent
dc34e6e3b6
commit
f51f6acb4d
1 changed files with 19 additions and 0 deletions
@ -0,0 +1,19 @@ |
||||
import { useEffect, useState } from 'react'; |
||||
|
||||
const useWindowDimensions = (): number | undefined => { |
||||
const [windowDimensions, setWindowDimensions] = useState<number | undefined>( |
||||
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; |
Loading…
Reference in new issue