DEV Community

Cover image for ⚛️ Demystifying React's Types: Component types

⚛️ Demystifying React's Types: Component types

Will T. on March 28, 2024

React's type system, when used with TypeScript, provides developers with a robust framework for building type-safe applications. Understanding the ...
Collapse
 
espired profile image
Avihay Menahem • Edited

Component that want to get children from type doesnt need to implicitly declare it.
Instead, use:
React.PropsWithChildren<T>

Collapse
 
itswillt profile image
Will T.

Hi, thanks for dropping by.

I think it's a choice/preference. React.PropsWithChildren can be used to mimic the old behavior of React.FC, but sometimes explicitly defining the children prop has been more useful to me, e.g. when you need to force it to be a required property, or slightly modify its type. I think there's good reasons why they decided to remove the implicit children prop from React.FC.

Collapse
 
pavelee profile image
Paweł Ciosek

Great post! 👏👏

Collapse
 
itswillt profile image
Will T.

Thanks! Hope it was helpful to you.

Collapse
 
gitkearney profile image
Kearney Taaffe

Spot on article! I have a cheat sheet similar to this to help me because sometimes I just can't remember how to include children as props :-D

Collapse
 
itswillt profile image
Will T.

I guess at some point you’ll no longer need that cheat sheet anymore 😛.

Collapse
 
insideee_dev profile image
insideee.dev

Great post!
Keep going sir <3

Collapse
 
itswillt profile image
Will T.

Thanks! Please look forward to the next article.

Collapse
 
dca123 profile image
Devinda Senanayaka

Nice article ! Just the explanation of ElementType I needed

Collapse
 
allbertuu profile image
Alberto Albuquerque

Great article

Collapse
 
huage404 profile image
Micah Hua

Good article, many times I like to use 'React.FC' to declare components, but I'm not sure why