代码之家  ›  专栏  ›  技术社区  ›  Marty

从ReactJS中的this.props.children获取高度

  •  0
  • Marty  · 技术社区  · 6 年前

    如何从孩子身上获得高度,作为道具传递?我是说:

    <div>
      {this.props.children} //get height?
    </div>
    1 回复  |  直到 6 年前
        1
  •  1
  •   Marty    6 年前

    断然的:

    this.childElement.offsetHeight //gives a height
    
    <div ref={(node) => (this.childElement = node)}>{children}</div>