@anton.bobrov/react-vevet-hooks
Version:
A collection of custom React hooks designed to seamlessly integrate with the `Vevet` library
35 lines (34 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIsMobile = void 0;
var react_1 = require("react");
var vevet_1 = require("vevet");
/**
* Custom React hook that determines if the current device is mobile.
*
* This hook uses the `vevet` library to check if the viewport
* corresponds to a mobile device. It initializes the state as `null`
* until the check is performed, after which it updates the state
* to either `true` or `false` based on the result.
*
* @example
* const MyComponent = () => {
* const isMobile = useIsMobile();
*
* return (
* <div>
* {isMobile === null
* ? 'Checking device type...'
* : isMobile
* ? 'You are using a mobile device.'
* : 'You are using a desktop device.'}
* </div>
* );
* };
*/
function useIsMobile() {
var _a = (0, react_1.useState)(null), isMobile = _a[0], setIsMobile = _a[1];
(0, react_1.useEffect)(function () { return setIsMobile(vevet_1.vevet.isMobile); }, []);
return isMobile;
}
exports.useIsMobile = useIsMobile;