mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
move menu links to map, add window-size hook
This commit is contained in:
35
apps/marketing/src/hooks/use-window-size.ts
Normal file
35
apps/marketing/src/hooks/use-window-size.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user