Javascript 如果组件存在,则隐藏
在这种情况下我应该使用ref吗?我想检查是否渲染了一个组件,然后使用该标记执行其他操作Javascript 如果组件存在,则隐藏,javascript,reactjs,jsx,Javascript,Reactjs,Jsx,在这种情况下我应该使用ref吗?我想检查是否渲染了一个组件,然后使用该标记执行其他操作 render(){ {isSomeOtherCondition && <CustomComponent {...props} />} <div className={classnames({'hide': isCustomCompoentExist })} >hide this if CustomComponent is rendered</div
render(){
{isSomeOtherCondition && <CustomComponent {...props} />}
<div className={classnames({'hide': isCustomCompoentExist })} >hide this if CustomComponent is rendered</div>
}
render(){
{isSomeOtherCondition&&}
如果呈现CustomComponent,则隐藏此选项
}
在提供的示例中,我们已经有一个变量定义了呈现
的时间。我们可以使用isSomeOtherCondition
隐藏
元素
render() {
return (
<div>
{
isSomeOtherCondition ?
<CustomComponent {...props} /> :
<div>hide this if CustomComponent is rendered</div>
}
</div>
);
}
render(){
返回(
{
还有其他情况吗?
:
如果呈现CustomComponent,则隐藏此选项
}
);
}
因此,如果
为其他条件
为真
,则渲染
。如果isSomeOtherCondition
发生错误,那么我们将渲染如果呈现CustomComponent,则隐藏此项
您无法判断是否渲染了它,但可以使用它用于隐藏/显示的相同条件。