【发布时间】:2021-04-16 23:00:29
【问题描述】:
我试图 curry styled 函数,但 react 似乎在运行时抛出错误。 (JSX 元素没有任何构造函数或调用签名)
这个想法是创建一个可重复使用的基本样式(无需设置其附加的元素)。
const template = baseStyle`
backgroundColor: reg
`
const Component1 = template(div)
const Component2 = template(a)
该函数接受 html 或样式组件。这是我到目前为止所做的,我很确定类型是关闭的。
export const baseStyle = (strings: TemplateStringsArray, ...rest: Interpolation<any>[]) => {
return (element: AnyStyledComponent): StyledComponent<any, any, any, any> => {
return styled(element)(strings, ...rest)
}
}
有没有办法做到这一点?
【问题讨论】:
标签: reactjs typescript styled-components