Reputation: 866
Let's say I have a React component called Link:
function Link(props) {
return <a href={props.url}>{props.children}</a>
}
This doesn't seem to work:
interface ILink {
url: string
}
function Link(props: React.FC<ILink>) { }
// Property 'url' does not exist on type 'FC<ILink>'.
// Property 'children' does not exist on type 'FC<ILink>'.
But as an arrow-function it instantly does work?
interface ILink {
url: string
}
const Link: React.FC<ILink> = (props) => { }
// Compiles
Upvotes: 1
Views: 238
Reputation: 866
You have to use the combo React.PropsWithChildren
and React.ReactElement
so it becomes:
function Link(props: PropsWithChildren<ILink>): ReactElement {}
Upvotes: 4