You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently ran into a situation where I converted a DOM element into a component, but kept the ref on it. Suddenly, the parts of my code that used the clientHeight of my ref no longer worked because apparently components only support offsetHeight. I now have two options:
use forwardRef to pass the reference to the DOM element from my component to the parent. This looks ugly.
swap clientHeight with offsetHeight, but that might miscalculate when it gets a border or pseudo-elements.
Is there a better way to get the client height of a component?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I recently ran into a situation where I converted a DOM element into a component, but kept the
ref
on it. Suddenly, the parts of my code that used theclientHeight
of myref
no longer worked because apparently components only supportoffsetHeight
. I now have two options:forwardRef
to pass the reference to the DOM element from my component to the parent. This looks ugly.clientHeight
withoffsetHeight
, but that might miscalculate when it gets a border or pseudo-elements.Is there a better way to get the client height of a component?
Beta Was this translation helpful? Give feedback.
All reactions