I am trying to find a position of a component rendered with React. I am using redux, so I had to modify the connect function to:
export default connect(mapStateToProps, mapDispatchToProps,null,{ withRef: true })(MyComponent);
Now I am getting a component back when I call:
class OneColumn extends Component {
componentDidMount(){
var input = this.refs.myComponentsRef.getWrappedInstance();
console.log(input); // Outputs > TheComponentIWant {props: Object, context: Object, refs: Object, updater: Object, _reactInternalInstance: ReactCompositeComponentWrapper…}
var inputRect = input.getBoundingClientRect();
console.log(inputRect); // Outputs error: Uncaught TypeError: input.getBoundingClientRect is not a function
}
//...
}
So I can get the component, however I cannot then get the boundingClientRect.
Anything I am overlooking?
Please help:)
I found an alternate solution that circumvents this problem: This post describes and refers to another post
Basically when the components starts rendering the components give a callback function where you store the positions of those components.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With