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

245
Views
Can you render react component to div with display none?

I need to render react component to div with id hover-countdown. So as the name says it is not visible when page load, but only on hover. Does this somehow affect ReactDOM render? Because i am not able to render it. Is there some other way? Thank you:)

const HoverCountdown = () => {

  return (
    <span>Countdown</span>
  );
};

document.addEventListener("DOMContentLoaded", () => {
  ReactDOM.render(
    <HoverCountdown />,
    document.getElementById("hover-countdown")
  );
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Does this somehow affect ReactDOM render?

Not really. It React only concerns itself with DOM updates.

If the element it renders inside is display: none then the React rendering process will generate the DOM inside that element.

Then, subsequent to the React rendering, the browser will convert the DOM to something rendered on screen (which will be nothing because the container is display: none).

about 4 years ago · Juan Pablo Isaza Report

0

If you set the visibility to hidden, hovering over the invisible component will not trigger the :hover styles to take effect.

What is odd is that if you inspect element and toggle the :hidden styles then it will properly show up.

const HoverCountdown = () => (
  <span>Countdown</span>
);

//document.addEventListener('DOMContentLoaded', () => {
  ReactDOM.render(
    <HoverCountdown />,
    document.getElementById('hover-countdown')
  );
//});
.wrapper {
  background: #EFE;
}

#hover-countdown {
  visibility: hidden; /* will render fine if removed */
}

#hover-countdown:hover {
  visibility: visible;
  color: #040;
  cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div class="wrapper">
  <div id="hover-countdown"></div>
</div>

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!