Course contentsShow
← React
Lesson 2394 of 2,39651. TypeScript with React BasicsFree lesson

Children: Opt-In vs Implicit

How React.FC made children always available; why explicit children: ReactNode in props is clearer intent.

Children: Opt-In vs Implicit

You'll learn why explicitly typing children in your props interface is clearer and more intentional than relying on automatic inclusion.

The React.FC Difference

When you use React.FC, it automatically includes children?: ReactNode in your component's props—whether you want it or not. This means every component typed with React.FC implicitly accepts children, even if it logically shouldn't:

const Avatar: React.FC<{ name: string }> = ({ name }) => {
  return <div className="avatar">{name}</div>;
};

// This compiles without error, but makes no sense:
<Avatar name="Alice">
  <span>What am I doing here?</span>
</Avatar>

The Opt-In Approach

Without React.FC, children are not automatically available. You must explicitly declare them in your props interface:

interface ButtonProps {
  onClick: () => void;
  children: ReactNode; // Opt-in: you declare it
}

const Button = ({ onClick, children }: ButtonProps) => {
  return <button onClick={onClick}>{children}</button>;
};

If a component shouldn't accept children, simply don't include children in the interface. TypeScript will prevent misuse:

interface BadgeProps {
  count: number;
  // No children property
}

const Badge = ({ count }: BadgeProps) => {
  return <span className="badge">{count}</span>;
};

// TypeScript error: Badge doesn't accept children ❌
<Badge count={5}>Hello</Badge>

Think of It Like a Door

Implicit children (React.FC) is like every room having a back door—whether it needs one or not. Opt-in children means you only install doors where they belong, making the architecture's intent obvious at a glance.

Key Takeaway: Explicitly typing children: ReactNode in your props interface communicates clear intent—this component expects children—while omitting it prevents misuse.