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

174
Visualizações
Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' error in React

I'm trying to make auto expanding (upwards) text-box with JavaScript in a React application. Got this error. Also tried using window.getElementbyId instead of but that doesn't work.

[![error image][1]][1]
   <ReactTextareaAutocomplete
   id="textbox"
   className="message-input"
   placeholder="Type your message.."/>
const tx = document.getElementsByTagName("ReactTextareaAutocomplete");
const maxheight = 100;
const normalheight = window.getComputedStyle(tx[0]).getPropertyValue('height').replace("px", "");
for (let i = 0; i < tx.length; i++) {
  tx[i].setAttribute("style", "margin-top:-3px;" + "height:" + (tx[i].scrollHeight > maxheight ? maxheight : tx[i].scrollHeight) + "px;overflow-y:hidden;");
  tx[i].addEventListener("input", OnInput, false);
}

function OnInput() {
  this.style.marginTop = (normalheight - this.style.height.replace("px", "")) + "px";
  this.style.height = "auto";
  this.style.height = (this.scrollHeight > maxheight ? maxheight : this.scrollHeight) + "px";
}


  


  [1]: <https://i.stack.imgur.com/1UbRS.png>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Implement useRef() instead to access the element.

Add the ref attribute on the element.

<ReactTextareaAutocomplete ref={rtaRef} />

And for the function:

const tx = useRef(null);

If you have multiple instances of the component, use the loop to create unique ref using the loop index.

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