@anton.bobrov/react-vevet-hooks
Version:
A collection of custom React hooks designed to seamlessly integrate with the `Vevet` library
38 lines (37 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useViewportSize = void 0;
var react_1 = require("react");
var vevet_1 = require("vevet");
var useOnResize_1 = require("./useOnResize");
/**
* Custom React hook that provides the current size of the viewport.
*
* This hook uses the `vevet` library to retrieve the current width and height
* of the viewport and updates the state whenever the viewport is resized.
*
* @example
* const MyComponent = () => {
* const { width, height } = useViewportSize();
*
* return (
* <div>
* Viewport Size: {width} x {height}
* </div>
* );
* };
*/
function useViewportSize() {
var _a = (0, react_1.useState)({
width: 0,
height: 0,
}), size = _a[0], setSize = _a[1];
(0, useOnResize_1.useOnResize)(function () {
return setSize({
width: vevet_1.vevet.viewport.width,
height: vevet_1.vevet.viewport.height,
});
}, []);
return size;
}
exports.useViewportSize = useViewportSize;