如何在React中根据其后代的className更改组件的className?

时间:2018-11-22 19:20:35

标签: reactjs dom classname

我有一个React App,其结果类似于以下内容:

[EDIT .:这不是源代码(不仅仅是在一个组件中),而是呈现的html(我认为足以描述问题)]:

<Component1 className="main-component1">
    <Something className="sub-component1"/>
    <SomethingDifferent className="sub-component2"/>
    <Something className="sub-component1"/>
</Component1>
<Component1 className="main-component1">
    <SomethingDifferent className="sub-component2"/>
    <SomethingDifferent className="sub-component2"/>
        <div className="popup"/>
    </SomethingDifferent>
    <Something className="subComponent1"/>
</Component1>
.
.
.

popup仅在特定情况下呈现。我想将其最高父级(className)的Component1更改为className="main-component1 containsPopup"。任何想法如何做到这一点?

我当时正在考虑使用Refs,但是在这种情况下我找不到合适的用法。

另一个想法是只使用一些查询过滤器来找到它,但是在我看来这并不是一个好方法。

任何想法我都会很高兴^ _ ^

0 个答案:

没有答案