You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
596 B
20 lines
596 B
3 years ago
|
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;
|