Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!