maslianok / react-resize-detector

A Cross-Browser, Event-based, Element Resize Detection for React
http://maslianok.github.io/react-resize-detector/
MIT License
1.25k stars 91 forks source link

Support for children DOM element #181

Closed chirag00757 closed 2 years ago

chirag00757 commented 3 years ago

Hi, I could not find any proper example for detecting width and height for children's elements. For example, I have parent

I can detect the width and height of the div className parent using react hook but if I want to detect the width and height of className child1 div then there is no example in the documentation of how to to do that. I tried by defining a new ref to child element but destructuring useResizeDetector() of className parent's width and height clashs with new child element.

Any help in that?

maslianok commented 2 years ago

If you can't attach react-resize-detector to the element directly you must pass the ref down the DOM tree and attach it to the target element or Component.

I'm sure you already solved the problem, but if you still have any questions - let me know. It will be much better if you provide a code snippet