Invariant Violation: Argument appears to not be a ReactComponent
Asked Answered
I

1

7

I need to find the offsetLeft of a component.

componentDidMount(){
        var tesNo =ReactDOM.findDOMNode(this.refs.dropDown.refs.input.offsetLeft)

    }
<ReactAutocomplete
    ref="dropDown"
   /*.......*/
/>

While debugging I get the value of the variable tesNo .After that I am getting this error:

Consider adding an error boundary to your tree to customize error handling behavior. Visit this site to learn more about error boundaries. Invariant Violation: Argument appears to not be a ReactComponent

How to solve this error?

Istria answered 1/3, 2019 at 6:54 Comment(0)
I
7

Found the answer by myself.

Since I am using react version: "^16.3.2" , I used createRef() API.

class Patient extends React.Component{
constructor(props){
    super(props)
    this.state = {
      postn:0
    }
this.dropDown=React.createRef()
}
componentDidMount(){
    let left = this.dropDown.current.refs.input.offsetLeft;
        this.setState({postn:left})
}
<ReactAutocomplete
    ref={this.dropDown}
   /*.......*/
/>
}
Istria answered 4/3, 2019 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.