Ignore:
Timestamp:
01/21/25 03:08:24 (3 days ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
0c6b92a
Message:

F4 Finalna Verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/react-use/lib/useWindowSize.js

    r0c6b92a r79a0317  
    55var useRafState_1 = tslib_1.__importDefault(require("./useRafState"));
    66var util_1 = require("./misc/util");
    7 var useWindowSize = function (initialWidth, initialHeight) {
    8     if (initialWidth === void 0) { initialWidth = Infinity; }
    9     if (initialHeight === void 0) { initialHeight = Infinity; }
    10     var _a = useRafState_1.default({
     7var useWindowSize = function (_a) {
     8    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;
     9    // Use the useRafState hook to maintain the current window size (width and height)
     10    var _e = useRafState_1.default({
    1111        width: util_1.isBrowser ? window.innerWidth : initialWidth,
    1212        height: util_1.isBrowser ? window.innerHeight : initialHeight,
    13     }), state = _a[0], setState = _a[1];
     13    }), state = _e[0], setState = _e[1];
    1414    react_1.useEffect(function () {
     15        // Only run the effect on the browser (to avoid issues with SSR)
    1516        if (util_1.isBrowser) {
    1617            var handler_1 = function () {
     18                var width = window.innerWidth;
     19                var height = window.innerHeight;
     20                // Update the state with the new window size
    1721                setState({
    18                     width: window.innerWidth,
    19                     height: window.innerHeight,
     22                    width: width,
     23                    height: height,
    2024                });
     25                // If an onChange callback is provided, call it with the new dimensions
     26                if (onChange)
     27                    onChange(width, height);
    2128            };
     29            // Add event listener for the resize event
    2230            util_1.on(window, 'resize', handler_1);
     31            // Cleanup function to remove the event listener when the component is unmounted (it's for performance optimization)
    2332            return function () {
    2433                util_1.off(window, 'resize', handler_1);
     
    2635        }
    2736    }, []);
     37    // Return the current window size (width and height)
    2838    return state;
    2939};
Note: See TracChangeset for help on using the changeset viewer.