0

I am trying to get div element in reactJS but I am not able to achieve it . I need some expert to look into my code and resolve my issue or new code snippet would be appreciated .

Thanks

Code

    this.divElement = React.createRef()

    const height = this.divElement.clientHeight
    this.setState({ height })

     <div
      className="col-2-3"
      ref={(divElement) => {
      this.divElement = divElement
      }}
      >
     </div>
React Guy
  • 7
  • 2

1 Answers1

1

You should use the current property:

this.divElement = React.createRef()

const height = this.divElement.current.clientHeight
this.setState({ height })

 <div
  className="col-2-3"
  ref={this.divElement}
  >
 </div>
Ramesh Reddy
  • 10,159
  • 3
  • 17
  • 32