Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const useResolutionSwitch = (outerWidth = 1000, timeout = 500): [boolean] => {
const [isMobileResolution, setMobileResolution] = React.useState(false);
const handleResolutionChange = (): void => setMobileResolution(window.outerWidth < outerWidth);
const listener = debounce(handleResolutionChange, timeout);
React.useEffect(() => {
window.addEventListener('resize', listener);
handleResolutionChange();
return (): void => window.removeEventListener('resize', listener);
}, []);
return [isMobileResolution];
};
exports.useResolutionSwitch = function (outerWidth, timeout) {
if (outerWidth === void 0) { outerWidth = 1000; }
if (timeout === void 0) { timeout = 500; }
var _a = React.useState(false), isMobileResolution = _a[0], setMobileResolution = _a[1];
var handleResolutionChange = function () { return setMobileResolution(window.outerWidth < outerWidth); };
var listener = uno_js_1.debounce(handleResolutionChange, timeout);
React.useEffect(function () {
window.addEventListener('resize', listener);
handleResolutionChange();
return function () { return window.removeEventListener('resize', listener); };
}, []);
return [isMobileResolution];
};