UNPKG

hooks-me

Version:

<div align="center"> <h1>hooks-me</h1> <div>React useful hooks.</div>

21 lines (20 loc) 714 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = require("react"); var useWindowSize = function () { var _a = (0, react_1.useState)({ width: window.innerWidth, height: window.innerHeight, }), windowSize = _a[0], setWindowSize = _a[1]; var callback = function () { setWindowSize({ width: window.innerWidth, height: window.innerHeight }); }; (0, react_1.useEffect)(function () { window.addEventListener("resize", callback); return function () { window.removeEventListener("resize", callback); }; }, []); return [windowSize.width, windowSize.height]; }; exports.default = useWindowSize;