2 lines
607 B
JavaScript
2 lines
607 B
JavaScript
import{useState as l}from"react";import{disposables as m}from'../utils/disposables.js';import{useIsoMorphicEffect as p}from'./use-iso-morphic-effect.js';function h(i){if(i===null)return{width:0,height:0};let{width:t,height:e}=i.getBoundingClientRect();return{width:t,height:e}}function w(i,t,e=!1){let[r,f]=l(()=>h(t));return p(()=>{if(!t||!i)return;let n=m();return n.requestAnimationFrame(function s(){n.requestAnimationFrame(s),f(u=>{let o=h(t);return o.width===u.width&&o.height===u.height?u:o})}),()=>{n.dispose()}},[t,i]),e?{width:`${r.width}px`,height:`${r.height}px`}:r}export{w as useElementSize};
|