move menu links to map, add window-size hook

This commit is contained in:
premiare
2023-08-18 19:35:45 +10:00
committed by Mythie
parent cd1af7b5d3
commit 0b5a550cd1
4 changed files with 102 additions and 58 deletions

View File

@ -0,0 +1,35 @@
import { useEffect, useState } from 'react';
// This hook is used to get the window size
// It returns an object with the width and height of the window
// Works with window resizing as well, not to be confused with isMobile from is-mobile package
interface WindowSize {
width: number;
height: number;
}
export function useWindowSize(): WindowSize {
const [windowSize, setWindowSize] = useState<WindowSize>({
width: 0,
height: 0,
});
const handleSize = () => {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
};
useEffect(() => {
handleSize();
window.addEventListener('resize', handleSize);
return () => {
window.removeEventListener('resize', handleSize);
};
}, []);
return windowSize;
}