Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
Calculate height and show ViewMore Content based on list items content in React js

I have a dynamic array which is coming from the server and i need to set viewMore link when the element height is greater than certain height. This viewMore content need to be shown like this.

<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>

is it possible to calculate the height and show another element based on this height?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use a ref in comibination with clientHeight like so:

const ulElementRef = useRef(null);

const ulHeight = elementRef.current?.clientHeight;

//...

<ul ref={ulElementRef} style={{ "max-height":  valListMaxHeight }}>{listItems}</ul>

Then you can use ulHeight for your condition.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda