我很难找到关于这个模式的一些文档。它有名字吗?
TextBase
是一个带样式的组件。所以我可以像下面这样扩展它:Text.H1 = withComponent('h1')
,但是我也想要传递html属性。因此就有了函数组件。然而,当我扩展我的Text
组件时,属性被覆盖了,导致所有组件都是h1的。
const Text = (props) => {
const { children, testid, ...rest } = props;
return <TextBase data-testid={testid} {...rest}>{children}</TextBase>
}
Text.defaultProps = {color: 'red'}
Text.H1 = Text
Text.H1.defaultProps = { as: 'h1'}
Text.H2 = Text
Text.H2.defaultProps = { as: 'h2'}
Text.H3 = Text
Text.H3.defaultProps = { as: 'h3'}
??
发布于 2019-08-07 09:36:05
尝试使用this绑定函数调用,或者使用箭头函数,或者使用bind手动绑定函数。我相信它会起作用的。引用错误就是所有这些
https://stackoverflow.com/questions/57390747
复制相似问题