Typing Props Without React.FC
What you'll learn: The modern, explicit way to type React components without relying on the React.FC utility.
The Preferred Pattern
Instead of wrapping your component type with React.FC, you can directly annotate your props parameter and return type:
interface ButtonProps {
label: string;
onClick: () => void;
disabled?: boolean;
}
const Button = (props: ButtonProps): JSX.Element => {
return <button onClick={props.onClick}>{props.label}</button>;
};
Why This Approach Wins
When you type props directly, you get complete control. You explicitly say "this function takes these props and returns JSX." There's no magic utility adding implicit children or other surprises.
Think of it like ordering a custom sandwich: you specify exactly what goes in it, rather than accepting a preset combo that includes things you might not want.
The Full Picture
With destructuring, it looks even cleaner:
const Button = ({ label, onClick, disabled = false }: ButtonProps): JSX.Element => {
return (
<button onClick={onClick} disabled={disabled}>
{label}
</button>
);
};
You can see at a glance what props flow in and what comes out. No need to understand what React.FC does behind the scenes—everything is right there in your function signature.
When You Need Children
If your component accepts children, just add them to your interface:
interface CardProps {
title: string;
children: React.ReactNode;
}
const Card = ({ title, children }: CardProps): JSX.Element => {
return (
<div>
<h2>{title}</h2>
{children}
</div>
);
};
Key Takeaway: The pattern (props: MyProps): JSX.Element gives you explicit, predictable type safety without hidden behaviors—making it the modern standard for typing React components.