【发布时间】:2020-12-12 16:32:57
【问题描述】:
【问题讨论】:
-
请注意,以后请复制并粘贴您的代码/错误并将其包装在三个反引号
```中,以便其他人使用。
标签: reactjs typescript styled-components
【问题讨论】:
``` 中,以便其他人使用。
标签: reactjs typescript styled-components
您可能错误地定义了您的open 属性。您还需要定义一个接口来声明您的属性。尝试将您的 transform 行更改为以下内容:
transform: ${props => props.open ? 'translateX(0)' : 'translateX(100%)'};
并添加一个这样使用的接口:
interface UlProps {
open: boolean;
}
const Ul = styled.ul<UlProps>`
...
`
【讨论】:
我相信您在不附带 ts 支持的打字稿文件中使用常规 styled components 库。
您必须使用命令 npm i --save-dev @types/styled-components 安装 typescript 版本。
然后你可以定义像这样的道具
const UI = styled.ul<{open: boolean}>`
\\your regular style here
`;
并像使用它
<UI open={open}>
{/*children here*/}
</UI>
参考:This blog
【讨论】: