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
?