I am wondering how I can find the DOM node of a React child. This question has been asked before, however in every solution I can find (like this one), the accepted answer makes use of ReactDOM.findDOMNode. I don't consider this to be an ideal solution since use of ReactDOM.findDOMNode is discouraged, and it may be deprecated in the future.
If have looked into creating a new ref with React.createRef() from cloneElement, but this doesn't seem to provide a way of accessing getBoundingClientRect() which I require.
ie.
// in constructor
this.childElement = React.createRef();
...
const newChild = React.cloneElement(
childElement,
{ ref: this.childElement }
);
Is there a way of accomplishing this without ReactDOM.findDOMNode?
<div ref={node => this.node = node} />for example?props.children.const childElement = React.Children.only(this.props.children);As shown above, this element is cloned and I try to assign a ref (but obviously the node doesn't seem to work as intended since I cannot callgetBoundingClientRect). This should effectively be the same as iterating through and assigning refs.