[英]how to type component using css emotion?
I have this component and I can't use the theme with typescript我有这个组件,我不能使用 typescript 的主题
const buttonDisabled = css`
color: ${({ theme }) => theme.color};
`;
How can I type this component?如何键入此组件?
error: No overload matches this call.
Overload 1 of 2, '(template: TemplateStringsArray, ...args: CSSInterpolation[]): SerializedStyles', gave the following error.
Argument of type '({ theme }: { theme: any; }) => any' is not assignable to parameter of type 'CSSInterpolation'.
Type '({ theme }: { theme: any; }) => any' is missing the following properties from type 'CSSInterpolation[]': pop, push, concat, join, and 28 more.
Take help from their official documentation it have everything related to create a component in emotion https://emotion.sh/docs/styled and Simplest way to create a component using emotion css is从他们的官方文档中获取帮助,它包含与创建情感组件https://emotion.sh/docs/styled和使用情感 css 创建组件的最简单方法相关的所有内容
import styled from '@emotion/styled'
const Button = styled.button`
color: turquoise;
`
render(<Button>This my button component.</Button>)
pass props传球道具
import "./styles.css";
import styled from "@emotion/styled";
export const DIV = styled.div`
background-color: pink;
color: ${(props) => props.color};
`;
export default function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<DIV color="blue">Hello World</DIV>
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.