source: imaps-frontend/node_modules/react-use/lib/useWindowSize.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useRafState_1 = tslib_1.__importDefault(require("./useRafState"));
6var util_1 = require("./misc/util");
7var useWindowSize = function (initialWidth, initialHeight) {
8 if (initialWidth === void 0) { initialWidth = Infinity; }
9 if (initialHeight === void 0) { initialHeight = Infinity; }
10 var _a = useRafState_1.default({
11 width: util_1.isBrowser ? window.innerWidth : initialWidth,
12 height: util_1.isBrowser ? window.innerHeight : initialHeight,
13 }), state = _a[0], setState = _a[1];
14 react_1.useEffect(function () {
15 if (util_1.isBrowser) {
16 var handler_1 = function () {
17 setState({
18 width: window.innerWidth,
19 height: window.innerHeight,
20 });
21 };
22 util_1.on(window, 'resize', handler_1);
23 return function () {
24 util_1.off(window, 'resize', handler_1);
25 };
26 }
27 }, []);
28 return state;
29};
30exports.default = useWindowSize;
Note: See TracBrowser for help on using the repository browser.