react-viewport-hooks
Version:
Get real viewport width & height
17 lines (14 loc) • 1.71 kB
JavaScript
import n,{useState as e,useEffect as t}from"react";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var r=function(){return(r=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n}).apply(this,arguments)},i={defaultVH:void 0,defaultVW:void 0,updateOnResize:!0},o=function(n){var o=r(r({},i),n),u=o.updateOnResize,a=o.defaultVW,d=o.defaultVH,f=e(a),c=f[0],w=f[1],v=e(d),s=v[0],l=v[1];return t((function(){var n=function(){window.innerWidth!==c&&w(window.innerWidth),window.innerHeight!==s&&l(window.innerHeight)};if(n(),u)return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[u,s,c]),{vw:c,vh:s}},u=function(e){return function(t){return function(i){return n.createElement(t,r({},i,o(e)))}}};export{o as useViewport,u as withViewport};
//# sourceMappingURL=react-viewport-hooks.esm.js.map