@anton.bobrov/react-vevet-hooks
Version:
A collection of custom React hooks designed to seamlessly integrate with the `Vevet` library
34 lines • 935 B
JavaScript
import { useState } from 'react';
import { vevet } from 'vevet';
import { useOnResize } from './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>
* );
* };
*/
export function useViewportSize() {
var _a = useState({
width: 0,
height: 0,
}), size = _a[0], setSize = _a[1];
useOnResize(function () {
return setSize({
width: vevet.viewport.width,
height: vevet.viewport.height,
});
}, []);
return size;
}
//# sourceMappingURL=useViewportSize.js.map