vtils
Version:
一个面向业务的 JavaScript/TypeScript 实用程序库。
34 lines (33 loc) • 1.01 kB
JavaScript
exports.__esModule = true;
exports.useWindowSize = void 0;
var _taro = require("@tarojs/taro");
var _react = require("react");
var getWindowSize = function getWindowSize() {
var _getSystemInfoSync = (0, _taro.getSystemInfoSync)(),
width = _getSystemInfoSync.windowWidth,
height = _getSystemInfoSync.windowHeight;
return {
width: width,
height: height
};
};
var useWindowSize = exports.useWindowSize = function useWindowSize(
// 不支持
_initialWidth,
// 不支持
_initialHeight) {
var _useState = (0, _react.useState)(getWindowSize),
size = _useState[0],
setSize = _useState[1];
(0, _react.useEffect)(function () {
var getWindowSizeCallback = function getWindowSizeCallback() {
setSize(getWindowSize());
};
_taro.onWindowResize == null || (0, _taro.onWindowResize)(getWindowSizeCallback);
return function () {
_taro.offWindowResize == null || (0, _taro.offWindowResize)(getWindowSizeCallback);
};
}, []);
return size;
};
;