sendou.ink/app/hooks/useWindowSize.ts
Kalle 9e829614ed
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
Replace react-use dependency with a few helpers
2026-06-12 22:40:50 +03:00

32 lines
644 B
TypeScript

import { useState } from "react";
import { useEventListener } from "./useEventListener";
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
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,
});
};
useEventListener("resize", handleSize);
// Set size at the first client-side load
useIsomorphicLayoutEffect(() => {
handleSize();
}, []);
return windowSize;
}