reactjs - 如何在 reactcommerce 的个人资料页面中隐藏 TagNav
问题描述
在reactionCommerce中,我想根据某些条件在配置文件组件/页面的导航栏中隐藏TagNav。我是 reactCommerce 的新手
解决方案
您需要TagNav
使用 Reaction Commerce 的组件 API 进行覆盖。
由于您只想自定义组件的呈现方式,我建议使用getRawComponent
获取 Reaction 的默认TagNav
组件而不使用其 HOC,然后扩展它并使用replaceComponent
.
import React from "react";
import { Components, getRawComponent, replaceComponent } from "@reactioncommerce/reaction-components";
const TagNav = getRawComponent("TagNav");
class CustomTagNav extends TagNav {
/**
* This implementation of render will override TagNav's default
*/
render() {
const { navbarOrientation, navbarPosition, navbarAnchor, navbarVisibility } = this.props;
// Provided that you want to return a whole different component tree if your condition matches
if (yourCondition) {
return (
{/* What you want to return if TagNav isn't shown */}
);
}
return (
<div className={`rui tagnav ${navbarOrientation} ${navbarPosition} ${navbarAnchor} ${navbarVisibility}`}>
<div className="navbar-header">
<Components.Button
primary={true}
icon="times"
status="default"
className="close-button"
onClick={this.props.closeNavbar}
/>
{this.props.children}
</div>
{this.renderShopSelect()}
<div className="navbar-items">
<Components.DragDropProvider>
<Components.TagList
{...this.props}
isTagNav={true}
draggable={true}
enableNewTagForm={true}
>
<div className="dropdown-container">
<Components.TagGroup
{...this.props}
editable={this.props.editable === true}
tagGroupProps={this.tagGroupProps(this.state.selectedTag || {})}
onMove={this.props.onMoveTag}
onTagInputBlur={this.handleTagSave}
onTagMouseOut={this.handleTagMouseOut}
onTagMouseOver={this.handleTagMouseOver}
onTagSave={this.handleTagSave}
/>
</div>
</Components.TagList>
</Components.DragDropProvider>
{this.props.canEdit && this.renderEditButton()}
</div>
</div>
);
}
}
replaceComponent("TagNav", CustomTagNav);
推荐阅读
- ajax - 来自一段时间的ajax表单请求 - 混淆变量
- android - 向浏览器发送多个 URI(通过 FileProvider 从内部存储打开 HTML 文件)
- python - 混合整数和列表索引时的numpy重新排列
- java - BroadcastReceiver onReceive() 方法不会在带有代码扫描器的设备上调用
- java - 我的过滤器拦截了对上下文根的请求,这是怎么发生的?
- sql-server - 如何在 sql server 中仅选择数字类型的 ccolumn 名称
- python - 在独立 pytest 测试中使用 unittest 类型断言(如 assertNotIn)的最佳实践?
- c++ - 使用 if 语句的 C++ 模板实例化
- sql - 查询中的 Blob 与连接以创建视图
- python - “没有名为 timedeltas 的模块未构建”使用 pyinstaller