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

256
Visualizações
How to check that my data has been passed to the variable before it is rendered?(useRef)

I have this button that appears only when its text overflows its parent container. So far it works but when I go to refresh the page I get a typeerror of "Cannot read properties of undefined (reading 'clientHeight')."

I believe this is because my variable el hasn't finished pulling my data from my useRef. How can I check that my variable has passed in my data successfully before being rendered?

const inputRef = useRef<HTMLDivElement>()
const checkOverflowing = () => {
        const el = inputRef.current
        const isOverflowing = el.clientHeight < el.scrollHeight
        return isOverflowing
    }

return (
<div ref={inputRef} className="comment-for-user">{review.comments}</div>

            <div className="show-more-360">
                {checkOverflowing() &&
                    <button className="show-more-button" onClick={handleEvent}>...show More</button>}
            </div>)
about 4 years ago · Santiago Gelvez
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