@anton.bobrov/react-vevet-hooks
Version:
A collection of custom React hooks designed to seamlessly integrate with the `Vevet` library
27 lines • 921 B
JavaScript
import { useState } from 'react';
import { vevet } from 'vevet';
import { useOnResize } from './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>
* );
* };
*/
export function useViewportOrientation() {
var _a = useState('portrait'), orientation = _a[0], setOrientation = _a[1];
useOnResize(function () { return setOrientation(vevet.viewport.isLandscape ? 'landscape' : 'portrait'); }, []);
return orientation;
}
//# sourceMappingURL=useViewportOrientation.js.map