use-mobile-detect-hook
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "use-mobile-detect-hook", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "The React hook to detect if the device is mobile or desktop.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -8,5 +8,6 @@ const { useEffect } = require('react'); | ||
const isWindows = () => Boolean(userAgent.match(/IEMobile/i)); | ||
const isSSR = () => Boolean(userAgent.match(/SSR/i)); | ||
const isMobile = () => Boolean(isAndroid() || isIos() || isOpera() || isWindows()); | ||
const isDesktop = () => !isMobile(); | ||
const isDesktop = () => Boolean(!isMobile() && !isSSR()); | ||
return { | ||
@@ -16,3 +17,4 @@ isMobile, | ||
isAndroid, | ||
isIos | ||
isIos, | ||
isSSR | ||
}; | ||
@@ -22,5 +24,6 @@ }; | ||
useEffect(() => {}, []); | ||
return getMobileDetect(navigator.userAgent); | ||
const userAgent = typeof navigator === 'undefined' ? 'SSR' : navigator.userAgent; | ||
return getMobileDetect(userAgent); | ||
}; | ||
module.exports = useMobileDetect; |
4546
23