use-table-tools
Version:
react hook for building powerful table components
23 lines • 950 B
JavaScript
import { useEffect, useState } from 'react';
export var isClient = typeof window === 'object';
export var useWindowSize = function (shouldDoCalculations) {
if (shouldDoCalculations === void 0) { shouldDoCalculations = 'yes'; }
var _a = useState({
width: isClient ? window.innerWidth : Infinity,
height: isClient ? window.innerHeight : Infinity,
}), state = _a[0], setState = _a[1];
useEffect(function () {
if (isClient && shouldDoCalculations === 'yes') {
var handler_1 = function () {
setState({
width: window.innerWidth,
height: window.innerHeight,
});
};
window.addEventListener('resize', handler_1);
return function () { return window.removeEventListener('resize', handler_1); };
}
}, [shouldDoCalculations]);
return state;
};
//# sourceMappingURL=use-window-size.js.map