【发布时间】:2018-08-05 03:08:14
【问题描述】:
我有以下组件:
const StyledH3 = styled.h3`
direction: ${(props) => (props.isRTL ? 'rtl' : 'ltr')};
`;
const H3 = ({ children }) => (
<StyledH3 isRTL={isChildrenRTL(children)}>
{children}
</StyledH3>
);
export default H3;
我想扩展它的样式,例如在不同的文件中:
import { H3 } from 'components';
const Title = styled(H3)`
background-color: red;
`;
我怎样才能做到这一点?
【问题讨论】:
-
类似
Comp.extend? -
@OrB 是的,但是扩展组件是一个样式化组件,而是一个返回样式化组件的 React 组件
-
@OrB 好的,所以我找到了同时使用
extend和withComponent的解决方案。即将发布。谢谢大佬