UNPKG

1 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = void 0;
8var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9var _react = require("react");
10var _isMobile = _interopRequireDefault(require("../isMobile"));
11var _useLayoutEffect = _interopRequireDefault(require("./useLayoutEffect"));
12/**
13 * Hook to detect if the user is on a mobile device
14 * Notice that this hook will only detect the device type in effect, so it will always be false in server side
15 */
16var useMobile = function useMobile() {
17 var _useState = (0, _react.useState)(false),
18 _useState2 = (0, _slicedToArray2.default)(_useState, 2),
19 mobile = _useState2[0],
20 setMobile = _useState2[1];
21 (0, _useLayoutEffect.default)(function () {
22 setMobile((0, _isMobile.default)());
23 }, []);
24 return mobile;
25};
26var _default = exports.default = useMobile;
\No newline at end of file