UNPKG

656 BJavaScriptView Raw
1import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2import { useState } from 'react';
3import isMobile from "../isMobile";
4import useLayoutEffect from "./useLayoutEffect";
5
6/**
7 * Hook to detect if the user is on a mobile device
8 * Notice that this hook will only detect the device type in effect, so it will always be false in server side
9 */
10var useMobile = function useMobile() {
11 var _useState = useState(false),
12 _useState2 = _slicedToArray(_useState, 2),
13 mobile = _useState2[0],
14 setMobile = _useState2[1];
15 useLayoutEffect(function () {
16 setMobile(isMobile());
17 }, []);
18 return mobile;
19};
20export default useMobile;
\No newline at end of file