react-div-100vh
Advanced tools
Comparing version 0.5.5 to 0.5.6
@@ -60,3 +60,3 @@ "use strict"; | ||
function use100vh() { | ||
var _a = react_1.useState(measureHeight()), height = _a[0], setHeight = _a[1]; | ||
var _a = react_1.useState(measureHeight), height = _a[0], setHeight = _a[1]; | ||
var wasRenderedOnClientAtLeastOnce = useWasRenderedOnClientAtLeastOnce(); | ||
@@ -68,8 +68,7 @@ react_1.useEffect(function () { | ||
var measuredHeight = measureHeight(); | ||
if (height !== measuredHeight) | ||
setHeight(measuredHeight); | ||
setHeight(measuredHeight); | ||
} | ||
window.addEventListener('resize', setMeasuredHeight); | ||
return function () { return window.removeEventListener('resize', setMeasuredHeight); }; | ||
}, [height, wasRenderedOnClientAtLeastOnce]); | ||
}, [wasRenderedOnClientAtLeastOnce]); | ||
return wasRenderedOnClientAtLeastOnce ? height : null; | ||
@@ -92,10 +91,10 @@ } | ||
react_1.useEffect(function () { | ||
if (isClient() && !wasRenderedOnClientAtLeastOnce) { | ||
if (isClient()) { | ||
setWasRenderedOnClientAtLeastOnce(true); | ||
} | ||
}, [wasRenderedOnClientAtLeastOnce]); | ||
}, []); | ||
return wasRenderedOnClientAtLeastOnce; | ||
} | ||
function isClient() { | ||
return typeof window !== 'undefined'; | ||
return typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
} |
@@ -37,3 +37,3 @@ var __assign = (this && this.__assign) || function () { | ||
export function use100vh() { | ||
var _a = useState(measureHeight()), height = _a[0], setHeight = _a[1]; | ||
var _a = useState(measureHeight), height = _a[0], setHeight = _a[1]; | ||
var wasRenderedOnClientAtLeastOnce = useWasRenderedOnClientAtLeastOnce(); | ||
@@ -45,8 +45,7 @@ useEffect(function () { | ||
var measuredHeight = measureHeight(); | ||
if (height !== measuredHeight) | ||
setHeight(measuredHeight); | ||
setHeight(measuredHeight); | ||
} | ||
window.addEventListener('resize', setMeasuredHeight); | ||
return function () { return window.removeEventListener('resize', setMeasuredHeight); }; | ||
}, [height, wasRenderedOnClientAtLeastOnce]); | ||
}, [wasRenderedOnClientAtLeastOnce]); | ||
return wasRenderedOnClientAtLeastOnce ? height : null; | ||
@@ -67,10 +66,10 @@ } | ||
useEffect(function () { | ||
if (isClient() && !wasRenderedOnClientAtLeastOnce) { | ||
if (isClient()) { | ||
setWasRenderedOnClientAtLeastOnce(true); | ||
} | ||
}, [wasRenderedOnClientAtLeastOnce]); | ||
}, []); | ||
return wasRenderedOnClientAtLeastOnce; | ||
} | ||
function isClient() { | ||
return typeof window !== 'undefined'; | ||
return typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
} |
{ | ||
"name": "react-div-100vh", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"description": "A workaround for the '100vh' issue in mobile browsers", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12125
173