I try to not instantiate my styled component in render method, but i need the props of my component to create style, can i do this with a simple function component outside render method ? I have the typescript following error :
No overload matches this call. Overload 1 of 2, '(props: Pick, HTMLElement>, "style" | "title" | "key" | "defaultChecked" | ... 250 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }, "style" | ... 257 more ... | "rowEnd"> & Partial<...>, "style" | ... 257 more ... | "rowEnd"> & { ...; } & { ...; }): ReactElement<...>', gave the following error. Type '{ children: Element[]; className: string; }' is missing the following properties from type 'Pick, HTMLElement>, "style" | "title" | "key" | "defaultChecked" | ... 250 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }, "style" | ... 257 more ... | "rowEnd"> & Partial<...>, "style" | ... 257 more ... | "rowEnd">': photo, rowStart, rowEnd Overload 2 of 2, '(props: StyledComponentPropsWithAs<"figure", any, { photo: Photo; rowStart: number; rowEnd: number; }, never>): ReactElement, string | ... 1 more ... | (new (props: any) => Component<...>)>', gave the following error. Type '{ children: Element[]; className: string; }' is missing the following properties from type 'Pick, HTMLElement>, "style" | "title" | "key" | "defaultChecked" | ... 250 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }, "style" | ... 257 more ... | "rowEnd"> & Partial<...>, "style" | ... 257 more ... | "rowEnd">': photo, rowStart, rowEnd
type MyProps = {
className: string,
photo: IPhoto,
rowStart: number,
rowEnd: number,
}
const Figure = styled.figure<{photo: IPhoto, rowStart: number, rowEnd: number}>`
grid-column-start: ${props => props.photo.colStart};
grid-column-end: ${props => props.photo.colEnd};
grid-row-start: ${props => props.rowStart};
grid-row-end: ${props => props.rowEnd};
`;
const Photo = (props: MyProps) => {
return (
<Figure className={props.className}>
<Link to={`/photo/${props.photo.id}`}>
<img src={props.photo.url_c} alt={props.photo.title} />
</Link>
<figcaption>{props.photo.title}</figcaption>
</Figure>
)
}
export default Photo;