ReactJS get rendered component height

前端 未结 9 1657
夕颜
夕颜 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条回答
  •  无人及你
    2020-12-29 03:06

    I'd rather do it in componentDidUpdate, but by making sure a condition is met to prevent an infinite loop:

      componentDidUpdate(prevProps, prevState) {
        const row = document.getElementById('yourId');
        const height = row.clientHeight;
        
        if (this.state.height !== height) {
          this.setState({ height });
        }
      }

提交回复
热议问题