Skip to content

QuizNot attempted

React.FC and children

With React 18+ types, does <Card title="x">hi</Card> compile?
const Card: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • No: FC no longer adds children; declare children: React.ReactNode (or use PropsWithChildren<P>)
  • Since @types/react 18, FC<P> is just (props: P) => ReactNode, so passing children to a component whose props don't declare them is an error
  • add children: React.ReactNode (or wrap with PropsWithChildren<P>) when the component really renders them.
  • Not 'FC always includes children implicitly': that was the React 17 typing, removed because it let components silently accept children they ignored.
  • Not typed as any: there is no implicit children at all.
  • Not 'never receive children': they can, once children is in the props type.