Closed jlevycpa closed 8 years ago
If you use paddings or margins, height will not be correct since it reports only height. If you then load css that adds paddings - react-height will not know about it. That is intentional. For performance. If you are not rendering 10000 collapsible rows in a table, I would recommend to switch to https://www.npmjs.com/package/react-element-resize instead. It gives you optionally debounced dimensions/offsets and is really accurate. We use it for all our layout elements (not for big table rows obviously).
Cheers!
Related to #5
Related to #9
You are absolutely right. I don't know why I didn't think of that. I forgot that I was using the Webpack style loader to dynamically inject css instead of having a static css file linked to my HTML template. The Bootstrap css was getting injected after all of the javascript had already executed. I switched the order of my entry points in my Webpack config (so the css entry point is before js) and it works perfectly.
Thanks for pointing me in the right direction!
I had the same problem at some point. Happy it helped!
I'm seeing a strange issue where the height reported is too small. I'm just trying to calculate the height of a simple Bootstrap Alert component:
I'm getting back a height of 18, though the actual height is closer to 50 with margins and padding. I tried to implement the logic of React Height myself, and was seeing similar behavior when querying the
offsetHeight
of the DOM node in a lifecycle function likecomponentDidMount
. However if I checked the DOM node height inside of asetTimeout
(even with a timeout of 0), I got the correct height.It seems like Chrome won't give the height until after the parent or maybe even the full page is rendered for some reason.
Have you ever run into this?