Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Did React.FC stop using PropsWithChildren

In my memory, you could write this:

const SomeComponent:FC<{label: string}> = ({label, children}) => (

and I even found some documentation claiming you can do it. When I try (with React version 18.2), I just get an error saying children is not a prop.

When I do this

const SomeComponent:FC<PropsWithChildren<{label: string}>> = ({label, children}) => (

it works fine, but that’s wordy. Did this used to work and they changed it and nobody told me? Why did they change it? And why did nobody tell me?

like image 853
Michael Lorton Avatar asked Sep 18 '26 15:09

Michael Lorton


1 Answers

they changed it! Implicit children prop removed from React.FunctionComponent types. in React version 18. you can check it here. Now it needs to be listed explicitly when defining props as mentioned in reactjs documentation

like image 168
monim Avatar answered Sep 21 '26 14:09

monim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!