react-tesna-utils
Version:
A versatile utility library featuring optimized functions for data manipulation, clipboard handling, text truncation, comparison, validation, and more. Designed for modern JavaScript and TypeScript projects with efficient and reusable solutions.
30 lines (29 loc) • 1.07 kB
JavaScript
'use client';
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useWindowSize = void 0;
const react_1 = require("react");
const useWindowSize = () => {
const [windowSize, setWindowSize] = (0, react_1.useState)({
width: window.innerWidth,
height: window.innerHeight
});
(0, react_1.useEffect)(() => {
// Handler to call on window resize
const handleResize = () => {
// Set window width/height to state
setWindowSize({
width: window.innerWidth,
height: window.innerHeight
});
};
// Add event listener
window.addEventListener('resize', handleResize);
// Call handler right away so state gets updated with initial window size
handleResize();
// Remove event listener on cleanup
return () => window.removeEventListener('resize', handleResize);
}, []); // Empty array ensures that effect is only run on mount
return windowSize;
};
exports.useWindowSize = useWindowSize;