DEV Community

Discussion on: Usage of `React.FC` from my experience

Collapse
 
levi2ki profile image
Andrew Makarov

There is another utility type for components, that should not accept childrens - React.VFC - that type does not extend props with children attribute.

Your screenshot with function Greeteng({ children }: FC) error:
React.FC is alias for type that represents function, not properties object, thats why you facing error. Most common way to define type for props in such situation is to use PropsWithChildren utility type from React

export default function Greeting({ children }: React.PropsWithChildren<MyAwesomeProps>) {...}
Enter fullscreen mode Exit fullscreen mode

Or if you don't need children just type props like these:

export default function Greeting({ a }: { a: string }) {...} // no children in props
export default function Greeting({ a }: MyAwesomeProps) {...} // no children in props
Enter fullscreen mode Exit fullscreen mode

You won't loose types in JSX code.

Collapse
 
sarathsantoshdamaraju profile image
Krishna Damaraju

PropsWithChildren is TIL 🙌
Thank you