不从 parent 的渲染方法中渲染组件与不从其自己的渲染方法中渲染组件之间的区别?

Differences between not rendering a component from within the parent's render method and not rendering the component from its own render method?

我的直觉是,选择不从 parent 的 render 方法中渲染组件与选择不从其自己的 [=14= 中渲染相同的组件是不同的] 方法;至少从幕后的角度来看,因为感知到的最终结果是相同的。

有人可以解释一下是否确实存在差异,它们是什么?

抱歉缺少代码示例,我会在有普通计算机可用时添加一些。

更新:

例如,从 parent 组件的 render 方法内部:

...
render() {
    return(
        <ParentComponent>
            {(this.state.renderSpecificChild) ? <SpecificChild /> : null}
            <SomeOtherChild />
        </ParentComponent>
    );
}
...

VS

来自 child 组件的渲染方法

...
render() {
    return(
        {(this.props.renderSelf) ? <div></div> : null}
    );
}
...

当 parent 的 render 方法看起来像这样时

...
render() {
    return(
        <ParentComponent>
            <SpecificChild />
            <SomeOtherChild />
        </ParentComponent>
    );
}
...

这取决于你想要什么。如果您有可在其他地方重用的 child 组件并且需要进行非渲染检查,那么您可以将它放在 child 组件中,否则如果您不想在另一部分进行此检查对于这个 child 的应用程序,您可以使其更具体,只需将其放在 parent.

如果你现在没有这个场景,那么你把它放在哪个场景中并不重要。如果你需要改变它,以后重构应该很容易。

回答我自己的问题,主要区别在于,当 parent 控制是否呈现 child 或不呈现时,组件获取 child 而不是卸载,在内部,React 清理了一切。如果 child 自己决定是否渲染某些东西,它的所有方法等都保留在内存中。