[英]How do you pass custom properties to TypeScript + StyledCompoments?
I'm getting the following error when trying to use Styled Compoments 3 with TypeScript: 尝试将Typed Compoments 3与TypeScript一起使用时出现以下错误:
TS2365: Operator '<' cannot be applied to types 'ThemedStyledFunction<{}, any, DetailedHTMLProps<TableHTMLAttributes<HTMLTableElement>, HTMLTableE...' and '{ bkgImg: any; }'.
TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
TS2693: 'string' only refers to a type, but is being used as a value here.
TS2604: JSX element type 'ContainerTable' does not have any construct or call signatures.
Hero.tsx Hero.tsx
import React from 'react';
import styled from 'styled-components';
const ContainerTable = styled("table")<{ bkgImg: string }>`
background-image: url(http://baseurl.com/${(props) => props.bkgImg});
`;
....
export const Hero = ({
heading,
bkgImg,
}) => (
<ContainerTable
bkgImg={bkgImg}
>
<tr>
<ContentTd>
<table>
<tr>
<td>
<H1>
{heading}
</H1>
</td>
<td>
</td>
</tr>
</table>
</ContentTd>
</tr>
</ContainerTable>
);
I'm calling this component like so: 我这样称呼这个组件:
<Hero
bkgImg="image.png"
heading={
<div>
Way to go! <br />
</div>
}
/>
I'm using: 我正在使用:
"styled-components": "3.3.2",
"react": "16.6.3",
What am I doing wrong here? 我在这里做错了什么?
How about: 怎么样:
import React from "react";
import styled from "styled-components";
const ContainerTable = styled.table`
background-image: url(http://baseurl.com/${(props: { bkgImg: string }) => props.bkgImg});
`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.