reagent

p-himik 2022-11-14T09:07:05.650299Z

How do I check whether rendering a child component actually resulted in some DOM? I have a parent component that accepts a child, if the child decides that it shouldn't be rendered for some reason, an "unknown value" icon should be displayed. So the problem is that the fact that something should be rendered is known only by children, and what exactly to display if nothing is rendered is known only by the parent. Of course, I can restructure the whole thing to accommodate this specific pattern. But I'd rather have it in a more generic way where a child can be any component. There's probably some CSS trick (probably the :not(:only-child) selector) that achieves the same. But maybe there's some other solution?

schadocalex 2022-11-14T09:53:51.146029Z

As far as I know you can't. I think the "where a child can be any component" may be solved by the fact a component needs data, and if it's not that independent, you can know if you have data for it to display something or not (but so the parent actually do the conditional rendering). Maybe with a bit more information about what is the parent I could help better.

p-himik 2022-11-14T09:58:05.853979Z

Nah, the CSS trick worked. :)

;; views.cljs
[:td
  [:span child]
  [:span {:class :unknown-value}
   "Unknown value"]]

;; styles.css
span:not(:empty) + .unknown-value {
    display: none;
}

👍 1
schadocalex 2022-11-14T09:58:22.267839Z

> As far as I know you can't confirmed by https://github.com/facebook/react/issues/5517

👍 1
schadocalex 2022-11-14T10:00:56.632489Z

Yes you mentioned the CSS trick so I was talking about another in-code solution (and you may have wanted to know if the child is actually rendered or not for app logic)

p-himik 2022-11-14T10:02:00.826459Z

Yeah, indeed, something like that would be useful. Good to know it's not feasible.

schadocalex 2022-11-14T10:03:35.713759Z

btw for the CSS :not has less support than :empty, so you may invert it and display:block when it's empty and none by default

p-himik 2022-11-14T10:04:11.466129Z

> :not has less support than :empty What do you mean by that?

schadocalex 2022-11-14T10:04:20.618289Z

browser support

p-himik 2022-11-14T10:05:41.529879Z

Ah, I'm fine with that, but thanks.