@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
1 lines • 691 B
JavaScript
exports.__esModule=!0,exports.useElementSize=function(){const[e,{width:t,height:n}]=r();return{ref:e,width:t,height:n}},exports.useResizeObserver=r;var e=require("react");const t={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0},n="undefined"!=typeof window;function r(){const r=(0,e.useRef)(0),u=(0,e.useRef)(null),[c,i]=(0,e.useState)(t),o=(0,e.useMemo)((()=>n?new ResizeObserver((e=>{const t=e[0];t&&(cancelAnimationFrame(r.current),r.current=requestAnimationFrame((()=>{u.current&&i(t.contentRect)})))})):null),[]);return(0,e.useEffect)((()=>(u.current&&(null==o||o.observe(u.current)),()=>{null==o||o.disconnect(),r.current&&cancelAnimationFrame(r.current)})),[u.current]),[u,c]}