1 import { useEffect, useState } from 'react';
3 import debounce from '@proton/utils/debounce';
5 const getWindowSize = (): [width: number, height: number] => {
6 return [window.innerWidth, window.innerHeight];
9 const useWindowSize = () => {
10 const [windowSize, setWindowSize] = useState(() => getWindowSize());
13 const reducer = (oldValue: [number, number], newValue: [number, number]) => {
14 if (oldValue[0] === newValue[0] && oldValue[1] === newValue[1]) {
20 const onResize = debounce(() => {
21 setWindowSize((old) => reducer(old, getWindowSize()));
24 window.addEventListener('resize', onResize);
25 setWindowSize((old) => reducer(old, getWindowSize()));
27 window.removeEventListener('resize', onResize);
34 export default useWindowSize;