Michael Lorton
Michael Lorton

Reputation: 44436

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?

Upvotes: 3

Views: 2439

Answers (1)

monim
monim

Reputation: 4383

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

Upvotes: 3

Related Questions