[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var tslib_1 = require("tslib");
|
---|
| 4 | var react_1 = require("react");
|
---|
| 5 | var useRafState_1 = tslib_1.__importDefault(require("./useRafState"));
|
---|
| 6 | var util_1 = require("./misc/util");
|
---|
| 7 | var 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 | };
|
---|
| 30 | exports.default = useWindowSize;
|
---|