UNPKG

@anton.bobrov/react-vevet-hooks

Version:

A collection of custom React hooks designed to seamlessly integrate with the `Vevet` library

31 lines (30 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useViewportOrientation = void 0; var react_1 = require("react"); var vevet_1 = require("vevet"); var useOnResize_1 = require("./useOnResize"); /** * Custom React hook that detects the current viewport orientation. * * This hook uses the `vevet` library to determine the orientation of the viewport * (either 'portrait' or 'landscape') and updates the state accordingly * whenever the viewport is resized. * * @example * const MyComponent = () => { * const orientation = useViewportOrientation(); * * return ( * <div> * Current Orientation: {orientation} * </div> * ); * }; */ function useViewportOrientation() { var _a = (0, react_1.useState)('portrait'), orientation = _a[0], setOrientation = _a[1]; (0, useOnResize_1.useOnResize)(function () { return setOrientation(vevet_1.vevet.viewport.isLandscape ? 'landscape' : 'portrait'); }, []); return orientation; } exports.useViewportOrientation = useViewportOrientation;