19 lines
407 B
TypeScript
19 lines
407 B
TypeScript
import { useState } from "react";
|
|
import { useEventListener } from "./useEventListener";
|
|
|
|
export const useWindowSize = () => {
|
|
const [windowSize, setWindowSize] = useState({
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
});
|
|
|
|
useEventListener("resize", () => {
|
|
setWindowSize({
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
});
|
|
});
|
|
|
|
return windowSize;
|
|
};
|