Tengo una matriz dinámica que proviene del servidor y necesito configurar el enlace viewMore cuando la altura del elemento es mayor que cierta altura. Esta vistaMás contenido debe mostrarse así.
<div id={`_message_detail_list${id}`}> <ul style={{ "max-height": valListMaxHeight }}>{listItems}</ul> <div> {viewMoreText (here i need to add another condition to check height of ul is greater than some threshold) && ( <div> <a id={`_primaryAction_${id}`} href="#" data-key={id} onClick={this.handleClick}> {viewMoreText} </a> </div>¿Es posible calcular la altura y mostrar otro elemento basado en esta altura?
Puede usar una referencia en combinación con clientHeight así:
const ulElementRef = useRef(null); const ulHeight = elementRef.current?.clientHeight; //... <ul ref={ulElementRef} style={{ "max-height": valListMaxHeight }}>{listItems}</ul> Entonces puede usar ulHeight para su condición.