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

254
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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