这是我的样式组件。
import * as React from 'react';
import styled from 'styled-components';
import { ComponentChildren } from 'app-types';
interface Props {
children: ComponentChildren;
emphasized: boolean;
}
const HeadingStyled = styled.h2`
${props => props.emphasized && css`
display: inline;
padding-top: 10px;
padding-right: 30px;
`}
`;
const Heading = (props: Props) => (
<HeadingStyled>
{props.children}
</HeadingStyled>
);
export default Heading;
我收到以下警告:
Property 'emphasized' does not exist on type 'ThemedStyledProps<DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, any>'.
Cannot find name 'css'. Did you mean 'CSS'?
我怎样才能让它工作?
原文由 user1283776 发布,翻译遵循 CC BY-SA 4.0 许可协议
styled("h2")<IProps>
。您可以从 文档 中阅读有关该模式的更多信息css
此处不需要,当您需要从函数中实际返回 CSS 时,将其作为帮助程序添加。查看 条件渲染。考虑到这些,组件变为:
css
的用例