source: imaps-frontend/node_modules/react-use/esm/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: 973 bytes
Line 
1import { useEffect } from 'react';
2import useRafState from './useRafState';
3import { isBrowser, off, on } from './misc/util';
4var useWindowSize = function (initialWidth, initialHeight) {
5 if (initialWidth === void 0) { initialWidth = Infinity; }
6 if (initialHeight === void 0) { initialHeight = Infinity; }
7 var _a = useRafState({
8 width: isBrowser ? window.innerWidth : initialWidth,
9 height: isBrowser ? window.innerHeight : initialHeight,
10 }), state = _a[0], setState = _a[1];
11 useEffect(function () {
12 if (isBrowser) {
13 var handler_1 = function () {
14 setState({
15 width: window.innerWidth,
16 height: window.innerHeight,
17 });
18 };
19 on(window, 'resize', handler_1);
20 return function () {
21 off(window, 'resize', handler_1);
22 };
23 }
24 }, []);
25 return state;
26};
27export default useWindowSize;
Note: See TracBrowser for help on using the repository browser.