ReactJS get rendered component height

前端 未结 9 1631
夕颜
夕颜 2020-12-29 02:29

I\'m attempting to integrate or create a React version of https://github.com/kumailht/gridforms, to do so I need to normalize the height of the columns inside of the row. Th

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 03:17

    A bit more late, but I have an approach which can be used without using the getElementById method. A class based component could be created and the sample code can be used.

    constructor(props) {
      super(props);
      this.imageRef = React.createRef();
    }
    
    componentDidMount(){
      this.imageRef.current.addEventListener("load", this.setSpans);
    }
    
    setSpans = () => {
      //Here you get your image's height
      console.log(this.imageRef.current.clientHeight);
    };
    
    render() {
      const { description, urls } = this.props.image;
      return (
        
    {description}
    ); }

提交回复
热议问题