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

103
Visualizações
Rendering null in react element prevents me from using css's :empty selector

To better explain my question, I'll use an example:

Let's say I have two react elements, which contain one another. Lets call the container Box, and the child Stuff. Box just renders a div with className="box" which surrounds the children it is given. Stuff most of the time renders something, but its render function can return null when it decides there's nothing to render.

Here's the twist: if <Box> is empty, I don't want to show it at all. So I decided to use css3 selectors, and write something like

.box:empty {
    display: none;
}

... which should work, except react renders a <noscript> tag, which prevents the browser from treating the parent .box element as empty...

Is there an elegant way around this? I'd like to keep the logic of determining emptiness inside of Stuff, and have Box just "look" at its contents and decide whether it wants to show anything or not.

UPDATE

This fiddle https://jsfiddle.net/69z2wepo/67543/ has an example of what I'm trying to do. Strangely, in that fiddle, it works, and react doesn't render <noscript> tags... why does it render <noscript>s in my code? In what cases does react choose to render <noscript>s?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Found the problem!

I was using an old version of react-css-modules (3.7.7). Upgrading to 4.1.0 fixed it.

Looks like this was a relatively recent fix, too: https://github.com/gajus/react-css-modules/commit/a9c8de252d5464037090e155c431abfe9f671531

over 4 years ago · Santiago Trujillo 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