Changeset 79a0317 for imaps-frontend/node_modules/react-use/esm
- Timestamp:
- 01/21/25 03:08:24 (3 months ago)
- Branches:
- main
- Parents:
- 0c6b92a
- Location:
- imaps-frontend/node_modules/react-use/esm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/react-use/esm/useWindowSize.d.ts
r0c6b92a r79a0317 1 declare const useWindowSize: (initialWidth?: number, initialHeight?: number) => { 1 interface Options { 2 initialWidth?: number; 3 initialHeight?: number; 4 onChange?: (width: number, height: number) => void; 5 } 6 declare const useWindowSize: ({ initialWidth, initialHeight, onChange, }?: Options) => { 2 7 width: number; 3 8 height: number; -
imaps-frontend/node_modules/react-use/esm/useWindowSize.js
r0c6b92a r79a0317 2 2 import useRafState from './useRafState'; 3 3 import { isBrowser, off, on } from './misc/util'; 4 var useWindowSize = function ( initialWidth, initialHeight) {5 if (initialWidth === void 0) { initialWidth = Infinity; }6 if (initialHeight === void 0) { initialHeight = Infinity; }7 var _ a= useRafState({4 var useWindowSize = function (_a) { 5 var _b = _a === void 0 ? {} : _a, _c = _b.initialWidth, initialWidth = _c === void 0 ? Infinity : _c, _d = _b.initialHeight, initialHeight = _d === void 0 ? Infinity : _d, onChange = _b.onChange; 6 // Use the useRafState hook to maintain the current window size (width and height) 7 var _e = useRafState({ 8 8 width: isBrowser ? window.innerWidth : initialWidth, 9 9 height: isBrowser ? window.innerHeight : initialHeight, 10 }), state = _ a[0], setState = _a[1];10 }), state = _e[0], setState = _e[1]; 11 11 useEffect(function () { 12 // Only run the effect on the browser (to avoid issues with SSR) 12 13 if (isBrowser) { 13 14 var handler_1 = function () { 15 var width = window.innerWidth; 16 var height = window.innerHeight; 17 // Update the state with the new window size 14 18 setState({ 15 width: wi ndow.innerWidth,16 height: window.innerHeight,19 width: width, 20 height: height, 17 21 }); 22 // If an onChange callback is provided, call it with the new dimensions 23 if (onChange) 24 onChange(width, height); 18 25 }; 26 // Add event listener for the resize event 19 27 on(window, 'resize', handler_1); 28 // Cleanup function to remove the event listener when the component is unmounted (it's for performance optimization) 20 29 return function () { 21 30 off(window, 'resize', handler_1); … … 23 32 } 24 33 }, []); 34 // Return the current window size (width and height) 25 35 return state; 26 36 };
Note:
See TracChangeset
for help on using the changeset viewer.