What syntax to pass type to Interface Props generic? (Cat must be type FC)
interface CatProps<T> {
value: T
}
const Cat: FC<CatProps<T>> = () => {
return <h1>Hello World!</h1>
}
const cat = <Cat<number> />
CodePudding user response:
Here's a complete example (based on @Alex Chashin's comment):
interface CatProps<T> {
value: T;
}
const Cat = <T extends any>({value}: CatProps<T>) => <h1>Hello {value}!</h1>
const cat = Cat({value: 'world'});
or if you want to pass a number:
const cat = Cat({value: 11});