3

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?

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144

1 Answers1

3

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

monim
  • 3,641
  • 2
  • 10
  • 25