reactjs - 如何取出传递给 Hoc 函数的道具
问题描述
我写了一个withHoc.js
,传递组件和wrappedComponent:
export const withHoc = ( WrappedComponent, Component ) => class WithHoc extends Component {
...
render() {
return (
<WrappedComponent>
<Component>
</WrappedComponent>
)
}
}
withWrappedHoc.js
并使用样式组件创建另一个:
const WrappedComponent = styled.div`
...
`
export const withWrappedHoc = (Component) =>
withComponent(Component, WrappedComponent )
与withWrappedHoc
相同withHoc
,只是它用我自己的自定义替换 WrappedComponent。
解决方案
使用 curry 对这些 hoc 函数进行模式化可能很清楚,如下所示:
export const withHoc = ( WrappedComponent ) => (Component) => class WithHoc extends Component {
...
render() {
return (
<WrappedComponent>
<Component>
</WrappedComponent>
)
}
};
const WrappedComponent = styled.div`
...
`
export const withWrappedHoc = withhoc(WrappedComponent);
推荐阅读
- node.js - 在 NodeJS 中重用 SerialPort 对象
- python - 如何使用 CRLB 绘制 RMSE 与 S/N 比?
- date - Kotlin 日期错误“类型不匹配:推断类型为日期?但预期日期”
- json - 如何在 grafana 中为 Loki 的 json 日志绘制图表?
- c# - 检查用户输入是否为字符串
- c# - 在 Rider 中折叠类字段和构造函数参数
- python - 伙计们,我们如何将 Tacotron 添加到 python 程序中,我制作了一个 AI 程序,我希望它有 Tacotron VCTK p240 的声音
- python - 基于当前日期的 Flask 名称记录文件
- r - 如何使用分类坐标微调 geom_segment
- python-3.x - 使用 Python 的 Systemtap