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

126
Views
React equivalent to document.getElementById for class-based component

I'm trying to have a regular HTML section in a React class-based component where I'm trying to change the background color on a state-based event. I'm trying to use a document.getElementById() to manipulate the DOM with vanilla JS but I'm not able to get to it. This is what I'm trying so far:

this.setState({state: true}, () => {
  if (this.props.settings?.use_colors) {
    const section = document.getElementById('section')
    const colors = ['red', 'green']
    for (let i=0; i<colors.length;) {
      section.style.backgroundColor = colors[i]
      if (condition) i++
      if (i = colors.length - 1) {
        i = 0;
      }
    }
  }
});

And this is the render/return section:

<section className="section" style={{ backgroundColor: colors[i] ?? undefined}}>
<Component>
  <Components>
    ...
  </Components>
</Component>
</section>

What would be the best way to grab that section?

about 4 years ago · Juan Pablo Isaza
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!