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

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

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