How to get the width of a react element

前端 未结 8 1249
灰色年华
灰色年华 2020-12-01 01:10

Im trying to create a range input that displays a tooltip right above the slider thumb.

I went through some vanilla JS examples online and it seems that I need to ha

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 02:00

        class MyComponent extends Component {
          constructor(props){
            super(props)
            this.myInput = React.createRef()
          }
    
          componentDidMount () {
            console.log(this.myInput.current.offsetWidth)
          }
    
          render () {
            return (
            // new way - as of React@16.3
            
    some elem
    // legacy way //
    this.myInput = ref}>some elem
    ) } }

提交回复
热议问题